· FabLab Westharima Team · Documentation · 7 min read
ImageMagick v7 Installation, Commands, and Options List
Explaining usage of ImageMagick, a powerful tool that can batch process image conversion, compression, resize, composition, etc. via command line. Comprehensively summarizing from installation methods to practical command examples for beginners.
ImageMagick is a powerful tool that can batch process image conversion, compression, resize, composition, etc. via command line. This article is “for first-time users”, combining installation methods, frequently used commands in list format, gentle terminology explanations, precautions, FAQ, and troubleshooting.
In ImageMagick v7 and later, all command operations are executed with
magickat the beginning (e.g.,magick input.jpg ... output.jpg). This is a mechanism to consistently call ImageMagick’s various functions (conversion, processing, information retrieval, etc.) by using the “magick” command (prefix). Especially on Windows, the traditionalconvertcommand conflicts with the OS standard file conversion command, so it’s safe to always usemagick.
What is ImageMagick?
Can execute image “conversion (JPEG→PNG, etc.)”, “size change”, “cropping”, “rotation”, “composition (watermark/logo)”, “optimization (compression)”, etc. via command.
Strong in batch processing (bulk processing of large files), high reproducibility (same command produces same result).
Available on Mac / Linux / Windows.
ImageMagick Installation
macOS (Using Homebrew is common and easy)
Install Homebrew (※Only those who haven’t installed)
Install imagemagick with Homebrew (open terminal and execute following command)
zsh
brew install imagemagick- Check version
zsh
magick -versionFrequently Used Commands List (Ready to Use)
| Command | Purpose/Description | Frequently Used Options (Description) | Usage Example |
|---|---|---|---|
| magick | Basic command for image conversion/processing (v7) | -resize: Change image size -quality: Specify compression rate/quality -strip: Remove metadata -auto-orient: Auto rotate based on EXIF info -background: Specify background color -gravity: Specify reference position (center, bottom right, etc.) -extent: Canvas expansion/cropping | magick in.jpg -auto-orient -resize 1200x -quality 85 -strip out.jpg → Auto rotate image, resize to 1200px width, compress, remove metadata and save |
| magick identify | Display image information | -format: Specify display format (%m:format, %w:width, %h:height, etc.) | magick identify -format "%m %wx%h %r\n" in.jpg → Display image format, size, color depth, etc. |
| magick mogrify | Destructive overwrite batch processing | -path: Specify output directory -format: Specify output format -resize: Resize -quality: Specify quality | magick mogrify -path dist -format jpg -resize 1200x -quality 85 src/*.png → Batch convert PNG images to JPEG, resize, and save to dist folder |
| magick montage | Tile images into one | -tile: Specify number of rows/columns to arrange (e.g., 3x) -geometry: Size and spacing of each image -background: Specify background color | magick montage a.jpg b.jpg c.jpg -tile 3x -geometry 400x400+10+10 -background white out.jpg → Arrange 3 images in 3 columns and compose into 1 image |
| magick composite | Composition (overlay, watermark) | -gravity: Specify composition position (e.g., southeast=bottom right) -geometry: Position adjustment (+X+Y) -dissolve: Specify transparency | magick composite -gravity southeast -geometry +20+20 -dissolve 30 wm.png in.jpg out.jpg → Overlay wm.png on bottom right of in.jpg at 30% transparency |
| magick compare | Compare 2 images (diff output/evaluation) | -metric PSNR/MSE/AE: Comparison metric (PSNR=quality, MSE=error, AE=number of diff pixels) -fuzz: Tolerance (color similarity judgment) | magick compare -metric AE a.jpg b.jpg diff.png → Output diff of a.jpg and b.jpg to diff.png and display number of diff pixels |
| magick -crop | Cropping | -gravity: Crop reference position +repage: Reset margin information | magick in.jpg -gravity center -crop 800x800+0+0 +repage out.jpg → Crop 800x800 from center of image |
| magick -rotate | Rotation/auto rotation | -auto-orient: Auto rotate with EXIF info -rotate: Rotate by specified angle | magick in.jpg -auto-orient -rotate 90 out.jpg → Auto rotate image with EXIF info, then rotate 90 degrees more |
| magick -colorspace | Color conversion (e.g., grayscale) | -colorspace Gray: Grayscale conversion -profile: Apply/convert ICC profile | magick in.jpg -colorspace Gray out.jpg → Convert image to grayscale (black and white) |
| magick -thumbnail | Thumbnail creation (fast) | -thumbnail: Fast resize -strip: Remove metadata -extent: Canvas expansion/cropping | magick in.jpg -thumbnail 400x400^ -gravity center -extent 400x400 -strip thumb.jpg → Create 400x400 square thumbnail with center trimming |
| magick -annotate | Text drawing | -font: Specify font -pointsize: Text size -fill: Text color -annotate: Specify drawing position/content | magick in.jpg -font Arial -pointsize 48 -fill white -gravity south -annotate +0+30 "Sample" out.jpg → Draw “Sample” in white text at bottom of image |
| magick | GIF optimization - Reduce animated GIF size | -coalesce: Make each frame complete image -fuzz: Color similarity composition -layers Optimize: Optimization processing | magick in.gif -coalesce -fuzz 5% -layers Optimize out.gif → Optimize animated GIF to reduce file size |
Hint: ImageMagick “argument order affects result”. Basically write in order of “input → processing → output”, and place processing options after input and before output.
Representative Options Quick Reference
| Function | Option Example/Description |
|---|---|
| Resize | -resize 1600x (long side to 1600px) / -resize 800x800^ (short side basis assuming overflow trimming) |
| Crop | -crop 800x800+X+Y / For center -gravity center -crop 800x800+0+0 +repage |
| Quality/Compression | -quality 75..85 (JPEG), -quality 75..85 -alpha quality=90 (WebP) |
| Color Space | -colorspace sRGB / Grayscale -colorspace Gray |
| Remove Metadata | -strip |
| Auto Rotate | -auto-orient |
| Text | -font -pointsize -fill -annotate +x+y "TEXT" |
| Transparency | PNG→JPG with white background -background white -alpha remove -alpha off |
Frequently Used Practical Recipes (Ready for Copy-Paste)
Convert PNG to JPG
magick in.png out.jpgConvert all PNGs to JPG
magick mogrify -format jpg *.pngResize image (maintain aspect ratio)
magick in.jpg -auto-orient -resize 1600x -quality 85 -strip out.jpgSquare thumbnail (center trim)
magick in.jpg -thumbnail 400x400^ -gravity center -extent 400x400 -strip thumb.jpgWatermark (overlay logo at bottom right at 30%)
magick composite -gravity southeast -geometry +20+20 -dissolve 30 logo.png in.jpg out.jpgBatch convert to WebP (high compression, high quality)
magick mogrify -path webp -format webp -quality 80 -resize 1600x -strip *.jpgConvert only first page of PDF to image (high resolution)
magick -density 200 input.pdf[0] -quality 90 -strip page1.jpgGrayscale + lightweighting
magick in.jpg -colorspace Gray -quality 75 -strip out.jpgGentle Terminology Explanation for Beginners
- DPI (resolution): Print resolution index. On Web, pixels (px) are mainly important, and DPI often doesn’t directly affect appearance.
- Pixel count (pixel dimensions): Image width×height. Directly connected to file size and appearance.
- Color space (sRGB/AdobeRGB, etc.): Color expression range. sRGB is safe for Web. Different color spaces cause color shift.
- EXIF/metadata: Shooting date/time, camera info, location info, etc. Can be deleted with
-strip, effective for privacy protection and lightweighting. - ICC profile: Describes monitor or color space characteristics. Apply/convert with
-profile. - Alpha channel: Transparency information. Used for background transparency in PNG, etc.
- Delegate: External library group for handling specific formats like HEIC/WebP/PDF. May not be able to read/write if not installed.
Precautions and Best Practices for Use
Caution with destructive commands:
mogrifyoverwrites. To protect original data, separate output destination with-pathor recommendmagick input outputformat.-qualityis not “quality%”: Mainly JPEG quantization intensity. Generally 75–85 is sufficient balance of high quality and small size.Color change problem: Color shifts when input/output color spaces differ. For Web purposes, explicitly state
-colorspace sRGBor-profile sRGB.icc.HEIC/WebP/PDF support: Environment needs
libheif,webp,ghostscript. Error “no delegate” if not installed.Memory/disk limits: For batch processing of ultra-high resolution, consider specifying limits like
-limit memory 1GiB -limit map 2GiB.File name handling: Enclose in quotes if containing spaces or Japanese (e.g.,
"magick \"入力 画像.jpg\" ...").Windows prohibits
convert: Conflicts with OSconvert. Always usemagick.Option order: Order of input → processing → output. Changing order changes result, which is ImageMagick’s characteristic.
Metadata handling: Drop EXIF with
-stripfor public use for privacy protection and lightweighting.
Frequently Asked Questions (FAQ)
| Q | A |
|---|---|
| Difference between v6 and v7? How to write? | In v7, magick prefix is basic. Traditional convert is available as magick convert for compatibility. On Windows, convert conflicts with other uses, so magick is only choice. |
| Want to reduce size while maintaining quality. | For JPEG, -quality 75..85 -strip -auto-orient is standard. Reducing pixels with -resize is very effective. For WebP, -format webp -quality 75..85 is effective. |
| Want to keep/remove EXIF. | To keep, do nothing. To remove, specify -strip. |
| Image color looks different. | Cause is input color space or ICC profile. Unify with -colorspace sRGB or apply -profile sRGB.icc. |
| When converting transparent PNG to JPEG, background becomes black/gray. | JPEG doesn’t support transparency. Apply to white etc.: magick in.png -background white -alpha remove -alpha off out.jpg. |
| Want to batch resize images in folder. | Execute like magick mogrify -path dist -resize 1200x -quality 85 -strip src/*.jpg. Avoid destroying original images with -path. |
Troubleshooting
| Error/Phenomenon | Solution |
|---|---|
| Error: command not found | Check installation and PATH. On mac, magick -version after brew install imagemagick. |
| Error: no decode delegate for this image format | Install corresponding library (HEIC→libheif, WebP→webp, PDF→ghostscript) and check again. |
| Error: not authorized PDF/PS read restrictions | Check security policy (policy.xml) or ghostscript installation. Adjust permission settings with safety in mind. |
| Error: insufficient memory | Adjust limits with -limit memory 1GiB -limit map 2GiB etc., lower resolution, secure free temp disk space. |
| Output is strange/not processed | Review option order (input→processing→output). Understand input info with magick identify before processing. |
On Windows, convert becomes different command | Always use magick. |
Summary
First use
**magick**, be conscious of input→processing→output order.Try commands and recipes in tables as-is, then batch with
mogrifywhen accustomed.Understanding color space, metadata, and
-qualitymeaning dramatically advances quality and size optimization.
When you notice errors or omissions, accuracy improves by installing necessary libraries (
ghostscript,libheif,webp, etc.), reviewing option order, and explicitly stating color space.

