ImageMagick Usage Examples
By Ercan - 13/04/2025
ImageMagick is a powerful open-source tool for creating, editing, and converting images directly from the command line.
It supports hundreds of image formats and offers a wide variety of operations, including resizing, cropping, filtering, color adjustments, annotations, and more.
Whether you want to process a single image or automate transformations on large image collections, ImageMagick provides a versatile and scriptable solution.
You can download ImageMagick by using link below.
https://imagemagick.org/script/download.php
⚡ Basic Image Operations
Convert image format:
convert input.png output.jpg
Display image information:
identify input.jpg
Get detailed metadata:
identify -verbose input.jpg
Resize image to width 800px (keep aspect ratio):
convert input.jpg -resize 800x output_resized.jpg
Resize to exact dimensions (ignore aspect ratio):
convert input.jpg -resize 800x600! output_exact.jpg
Crop image (x=100, y=50, width=400, height=300):
convert input.jpg -crop 400x300+100+50 output_cropped.jpg
🎨 Color & Effects
Convert to grayscale:
convert input.jpg -colorspace Gray output_gray.jpg
Adjust brightness/contrast:
convert input.jpg -brightness-contrast 10x15 output_bc.jpg
Apply sepia tone:
convert input.jpg -sepia-tone 80% output_sepia.jpg
Blur image:
convert input.jpg -blur 0x8 output_blur.jpg
Sharpen image:
convert input.jpg -sharpen 0x2 output_sharpen.jpg
Negate colors (invert):
convert input.jpg -negate output_negate.jpg
🖋️ Text & Annotation
Add simple text:
convert input.jpg -gravity South -pointsize 36 -annotate 0 "Sample Text" output_text.jpg
Add watermark/logo:
composite -gravity southeast watermark.png input.jpg output_watermarked.jpg
Draw shapes (rectangle example):
convert input.jpg -fill none -stroke red -strokewidth 5 -draw "rectangle 50,50 200,200" output_rect.jpg
🗂️ Batch Processing Examples
Resize all .png images in a directory:
mogrify -resize 800x *.png
Convert all .png to .jpg:
mogrify -format jpg *.png
Add watermark to all images:
for f in *.jpg; do composite -gravity southeast watermark.png "$f" "wm_$f"; done
Convert all images to grayscale:
mogrify -colorspace Gray *.jpg
Crop all images to 400x300:
mogrify -crop 400x300+0+0 *.jpg
🧪 Advanced Examples
Combine multiple images into a single montage:
montage img1.jpg img2.jpg img3.jpg -tile 3x1 -geometry +10+10 montage.jpg
Create an animated GIF from images:
convert -delay 20 frame*.png -loop 0 animation.gif
Add border to an image:
convert input.jpg -bordercolor black -border 10x10 output_border.jpg
Overlay semi-transparent rectangle:
convert input.jpg -fill "rgba(255,0,0,0.25)" -draw "rectangle 50,50 200,200" output_overlay.jpg
Resize and compress images for web:
convert input.jpg -resize 1024x768 -quality 85 output_web.jpg
🚀 Final Notes
ImageMagick provides a comprehensive suite of tools for image manipulation, suitable for single files or automated pipelines.
It supports a huge variety of formats and operations, making it ideal for conversion, editing, filtering, and batch processing.
💡 Pro tip: Always work on copies of original images when running batch operations. Commands like mogrify overwrite files by default, so backups are recommended.
With ImageMagick, you can efficiently enhance, standardize, and automate image processing tasks across any project.
Tags: imagemagick
