Resize ImageMagick Files Safely with mogrify-im6.q16
You will finish with a repeatable way to resize one or more images using the installed ImageMagick 6 command, while keeping an untouched copy until the result has been checked. The examples use ImageMagick 6.9.12-98 Q16 from the imagemagick-6.q16 package.
The route
Jump straight to the step you need, or tick off Done means at the end.
Allow about fifteen minutes. You need a shell, readable image files, and a writable working directory. The command is normally unprivileged. Use sudo only when the input or output directory is genuinely restricted, and check ownership and permissions before changing them.
Warning
mogrify writes changes back to the input file by default. Resizing, rotating, stripping metadata or changing format can be difficult or impossible to undo. Work on a copy, or use -path to write a separate result.
1. Check the installed command
Confirm which executable will run and record its version. These are read-only checks:
$ command -v mogrify-im6.q16
/usr/bin/mogrify-im6.q16
$ mogrify-im6.q16 -version
Version: ImageMagick 6.9.12-98 Q16 x86_64 18038
The unqualified command may be available as mogrify or mogrify-im6, but this guide uses the package-specific name so that scripts do not accidentally select another ImageMagick installation. The installed manual describes the same program under all three names.
Checkpoint: if command -v finds nothing, stop and install or enable the package through your normal system-management process. Do not copy a binary into a shared directory just to make a script pass.
2. Inspect the input before changing it
Use identify to see the format and dimensions. It does not alter the image:
$ identify /path/to/photo.jpg
/path/to/photo.jpg JPEG 4032x3024 4032x3024+0+0 8-bit sRGB 2.1MiB 0.000u 0:00.000
Exact statistics vary. Check the filename, format and dimensions, then make a backup before an in-place operation:
$ cp --preserve=all /path/to/photo.jpg /path/to/photo.jpg.before-mogrify
$ test -s /path/to/photo.jpg.before-mogrify && echo "backup ready"
backup ready
Keep the backup while you inspect the result. If the source is part of a large batch, copy the whole batch to a temporary or staging directory first rather than relying on a single manually selected file.
3. Write a resized copy with -path
The manual lists -path as the destination directory for written images. This is the safest form for a simple conversion: the source remains in place and the output keeps the input filename.
$ mkdir -p /path/to/resized
$ mogrify-im6.q16 -path /path/to/resized -resize '1200x1200>' /path/to/photo.jpg
$ identify /path/to/resized/photo.jpg
/path/to/resized/photo.jpg JPEG 1200x900 1200x900+0+0 8-bit sRGB 184KiB 0.000u 0:00.000
1200x1200> means fit within a 1200 by 1200 box, reducing only images that are larger. The aspect ratio is preserved, so a 4032 by 3024 photograph becomes 1200 by 900. The quotes protect the greater-than character from shell interpretation. The original remains 4032 by 3024.
Checkpoint: verify both files and compare their dimensions:
$ identify /path/to/photo.jpg /path/to/resized/photo.jpg
/path/to/photo.jpg JPEG 4032x3024 ...
/path/to/resized/photo.jpg JPEG 1200x900 ...
4. Apply a deliberate in-place change
Once the copy has passed inspection, you can change a disposable or backed-up file directly. This example resizes a copy to fit within 800 by 800 pixels:
$ cp --preserve=all /path/to/photo.jpg /path/to/photo-working.jpg
$ mogrify-im6.q16 -resize '800x800>' /path/to/photo-working.jpg
$ identify /path/to/photo-working.jpg
/path/to/photo-working.jpg JPEG 800x600 800x600+0+0 8-bit sRGB ...
The command's successful exit status means the operation completed; it does not prove that the dimensions suit your application. Keep checking the output explicitly. To undo this example, remove the working file and copy the preserved original back:
$ cp --preserve=all /path/to/photo.jpg /path/to/photo-working.jpg
If you changed the original itself, restore the .before-mogrify backup instead. Do not delete that backup until the replacement has been opened and checked.
5. Process a batch without losing the boundary
Pass several input files after the options, or use a carefully scoped shell glob. Put the results in a separate directory:
$ mkdir -p /path/to/resized-jpegs
$ mogrify-im6.q16 -path /path/to/resized-jpegs -resize '1600x1600>' /path/to/source/*.jpg
$ find /path/to/resized-jpegs -maxdepth 1 -type f -name '*.jpg' -print
/path/to/resized-jpegs/one.jpg
/path/to/resized-jpegs/two.jpg
Check that the glob matches exactly the files you intend before running the command. A broad pattern can include originals, backups or files from a previous run. The shell expands the glob before mogrify starts, so an unexpected match is a destructive error, not a filter that the program will correct.
For a dry inspection, use printf '%s\n' /path/to/source/*.jpg first. If the pattern matches nothing, some shells pass the literal pattern to the program, which then reports an input error. Use an explicit file list when the batch needs stronger review.
6. Handle metadata and output format carefully
-strip removes profiles and comments. That can reduce file size, but it can also remove colour profiles, orientation data or other information your workflow needs. Test it on a copy:
$ cp --preserve=all /path/to/photo.jpg /path/to/photo-no-metadata.jpg
$ mogrify-im6.q16 -strip /path/to/photo-no-metadata.jpg
$ identify -verbose /path/to/photo-no-metadata.jpg | grep -E 'Geometry:|Profiles:|Comment:'
Do not assume that a missing line means every kind of metadata has gone; inspect the file with a metadata tool appropriate to your format if that distinction matters.
The output format normally follows the filename suffix or the input's detected format. If you need another format, use a new suffix in a separate destination and verify it afterwards. A failed or unexpected conversion is easier to recover from when the source has not been overwritten.
Done means
- You confirmed the executable and ImageMagick version.
- You inspected the input dimensions before choosing a resize geometry.
- You used
-pathor a preserved backup before changing image data. - You checked the resulting files with
identify. - Your batch glob matched only the intended inputs.
- You treated
-stripas a data change and tested it on a copy.