Resize and Inspect Images Safely with ImageMagick 6
You will turn an image into a smaller copy, confirm its dimensions and format, and avoid the easy mistake of overwriting the source. This guide uses the installed Debian package imagemagick-6.q16, which provides ImageMagick 6.9.12-98 with Q16 support. Allow about 10 minutes if the package is already installed.
The route
Jump straight to the step you need, or tick off Done means at the end.
Prerequisites: a shell, an input image you can read, and a directory where you can write the output. The examples use convert-im6.q16 and identify-im6.q16, the versioned commands installed on this system.
1. Check the installed commands and source image
Start by checking the program version and the input file. This catches a missing package and confirms that you are measuring the file you think you are measuring.
convert-im6.q16 -version
identify-im6.q16 /path/to/input.jpg
The first command should report ImageMagick 6.9.12-98 and Q16 on this machine. The second prints properties such as the format, width, height, colour depth and file size. Its output will vary with the image, but it should name the input and include dimensions such as 1920x1080.
Use a real path in place of /path/to/input.jpg. Do not put a wildcard in this first check: identify-im6.q16 *.jpg is useful later, but it can produce a long list and make it easy to inspect the wrong file.
Checkpoint
You have a readable input file, know its current dimensions, and have confirmed which ImageMagick 6 binary is running.
2. Make a proportional smaller copy
Use -resize with a maximum width and height, then give the output a different filename. The > modifier means "only shrink images larger than this size". It prevents a small source from being enlarged.
convert-im6.q16 /path/to/input.jpg \
-resize '1200x1200>' \
/path/to/output-small.jpg
The output keeps the source aspect ratio. A landscape image might become 1200x675; a portrait image might become 800x1200. The command writes a new file and leaves input.jpg unchanged.
Verify both files explicitly:
identify-im6.q16 /path/to/input.jpg /path/to/output-small.jpg
test -s /path/to/output-small.jpg && echo "output exists and is non-empty"
Quote the geometry as shown. In an interactive shell, an unquoted > is redirection syntax rather than part of the ImageMagick argument. The backslash at the end of the first line is also part of the shell command: it joins the next line.
3. Convert to a different format
ImageMagick normally infers the output format from the filename extension. To make a PNG copy, keep the input first and use a .png output name:
convert-im6.q16 /path/to/input.jpg \
-resize '1200x1200>' \
/path/to/output-small.png
Check that the result is actually PNG rather than trusting the name:
identify-im6.q16 -format '%m %wx%h %b\n' /path/to/output-small.png
The output should have three fields: PNG, dimensions such as 1200x675, and a byte count. The -format option controls this compact output. %m is the format, %w and %h are width and height, and %b is the file size.
JPEG and PNG have different strengths. JPEG is usually a practical choice for photographs. PNG is usually better for sharp text, diagrams and transparency. Conversion can discard information, so preserve the original and inspect the result before replacing anything.
4. Control JPEG size deliberately
For a JPEG output, -quality accepts a value from 0 to 100. Higher values usually produce a larger file with less visible compression, but the result depends on the image.
convert-im6.q16 /path/to/input.png \
-resize '1600x1600>' \
-quality 85 \
/path/to/photo-web.jpg
Measure the result and compare it visually with the source:
identify-im6.q16 -format '%m %wx%h %b\n' /path/to/photo-web.jpg
ls -lh /path/to/input.png /path/to/photo-web.jpg
Do not treat 85 as a universal quality target. If text has ringing or fine detail has disappeared, try a higher value. If the file is still too large, reduce the dimensions first or try a lower value, then inspect again.
5. Process several files without changing the originals
For a small, known set of files, name each input and output explicitly. This is more typing, but it makes the mapping auditable and avoids accidental overwrites.
convert-im6.q16 ./photo-01.jpg -resize '1200x1200>' ./web-photo-01.jpg
convert-im6.q16 ./photo-02.jpg -resize '1200x1200>' ./web-photo-02.jpg
identify-im6.q16 ./web-photo-01.jpg ./web-photo-02.jpg
When using a wildcard, remember that one convert invocation treats multiple input images as an image sequence. It may combine or process them differently from the one-input, one-output pattern. A shell loop keeps each output separate:
Create ./web before running that loop, and inspect the list first:
mkdir -p ./web
printf '%s\n' ./photos/*.jpg
If the glob matches nothing, some shells pass the literal pattern to the command. Treat an error as a reason to check the directory, not as a signal to broaden the pattern.
for input in ./photos/*.jpg; do
output="./web/$(basename "$input")"
convert-im6.q16 "$input" -resize '1200x1200>' "$output"
done
6. Avoid the destructive shortcut
mogrify-im6.q16 is designed to modify images in place. The manpage distinguishes it from convert-im6.q16: mogrify overwrites the original, while convert writes to another output file.
Warning
Do not use mogrify on the only copy of a photograph, scan or asset. In-place resizing and format changes can be difficult or impossible to undo, and a failed operation may leave you with no clean source.
If you must use it on disposable copies, make a backup first:
cp -- ./input.jpg ./input.jpg.before-mogrify
mogrify-im6.q16 -resize '1200x1200>' ./input.jpg
identify-im6.q16 ./input.jpg
To undo that specific example, restore the backup only after checking its contents:
identify-im6.q16 ./input.jpg.before-mogrify
cp -- ./input.jpg.before-mogrify ./input.jpg
The ordinary convert examples need no elevated privileges. If a command reports permission denied, fix ownership or choose a directory you can write to; do not reach for sudo merely to hide a path mistake.
Common failure checks
- "no decode delegate" or an unreadable file: check the path, file permissions and actual file type with
file /path/to/input. A filename extension does not prove the contents. - Output is unexpectedly large: check both dimensions and bytes with
identify. Resizing alone does not guarantee a small file, especially for noisy photographs. - Output is blank or visually wrong: stop and inspect the source and output separately. Do not overwrite the source while troubleshooting.
- Permission denied: write to a directory you own, or ask the directory administrator. Image conversion itself does not require root.
- Command behaves differently from this guide: check
convert-im6.q16 -version. ImageMagick 7 uses different command naming, while this guide is for the installed ImageMagick 6 package.
Done means
- The installed ImageMagick version and input dimensions are known.
- The resized or converted file has a separate output path.
identify-im6.q16confirms the output format, dimensions and size.- The original remains available, or a verified backup exists before any in-place operation.