| name | Image Files |
| description | Image manipulation using ImageMagick command-line tools for resizing, converting, optimizing, and batch processing |
Image Files
Instructions
When helping users work with image files, follow these guidelines:
-
Tool Availability: ImageMagick is installed and available on the system path. Use magick command (modern syntax) or legacy commands (convert, identify, mogrify)
If it is not on the path look in C:\Program Files\ImageMagick-7.1.2-Q16-HDRI
-
Modern vs Legacy Syntax:
- Modern (ImageMagick 7+):
magick convert input.jpg output.png
- Legacy (ImageMagick 6):
convert input.jpg output.png
- Try modern syntax first, fall back to legacy if command not found
-
Common Operations:
- Resize: Use
-resize with geometry (e.g., 800x600, 50%, 800x)
- Convert Format: Change file extension (e.g.,
.jpg to .png)
- Quality: Use
-quality for JPEG compression (1-100)
- Strip Metadata: Use
-strip to remove EXIF data
- Batch Processing: Use
mogrify for in-place edits or shell loops for batch conversions
-
Preserve Aspect Ratio: Use geometry without ! suffix (e.g., 800x600 not 800x600!)
-
Output Paths: Always specify full output path to avoid overwriting originals
-
Format Support: Common formats include JPG, PNG, GIF, BMP, TIFF, WebP, PDF
-
Error Handling: Check file exists before processing, verify output was created
-
Performance: For batch operations, process files in parallel if system has multiple cores
Examples
Example 1: Resize Single Image
User: Resize this image to 800px wide, maintaining aspect ratio
Claude: I'll use ImageMagick to resize the image:
- Preserve aspect ratio with 800x geometry
- Keep original format
- Save to new filename to preserve original
magick convert input.jpg -resize 800x output.jpg
Example 2: Batch Convert and Optimize
User: Convert all PNG files to JPEG and reduce file size
Claude: I'll batch convert PNG to JPEG with optimization:
- Strip metadata with -strip
- Set quality to 85 (good balance)
- Process all PNG files in directory
for file in *.png; do magick convert "$file" -strip -quality 85 "${file%.png}.jpg"; done
Example 3: Generate Thumbnails
User: Create thumbnails for all images in a folder
Claude: I'll generate thumbnails:
- Resize to 200x200 (constrained, maintain aspect)
- Save with _thumb suffix
- Preserve format
for img in *.jpg; do magick convert "$img" -resize 200x200 "thumbs/${img%.jpg}_thumb.jpg"; done
Example 4: Get Image Information
User: What are the dimensions of this image?
Claude: I'll use identify to get image details:
magick identify input.jpg
# or: identify input.jpg
Reference Implementation Details
Common ImageMagick operations and patterns.
Basic Operations
Resize Images
Maintain Aspect Ratio:
magick convert input.jpg -resize 800x output.jpg
magick convert input.jpg -resize x600 output.jpg
magick convert input.jpg -resize 800x600 output.jpg
magick convert input.jpg -resize 50% output.jpg
Force Exact Dimensions (distorts if needed):
magick convert input.jpg -resize 800x600! output.jpg
Resize and Crop to Exact Dimensions:
magick convert input.jpg -resize 800x600^ -gravity center -extent 800x600 output.jpg
Convert Formats
magick convert input.jpg output.png
magick convert input.png -quality 90 output.jpg
magick convert input.tiff output.jpg output.png
magick convert document.pdf page-%03d.jpg
Optimize Images
JPEG Optimization:
magick convert input.jpg -quality 85 output.jpg
magick convert input.jpg -strip -quality 85 output.jpg
magick convert input.jpg -interlace Plane -quality 85 output.jpg
PNG Optimization:
magick convert input.png -strip output.png
magick convert input.png -colors 256 output.png
Crop and Trim
magick convert input.jpg -crop 800x600+100+50 output.jpg
magick convert input.jpg -trim output.jpg
magick convert input.jpg -border 10x10 -bordercolor white output.jpg
Image Information
magick identify input.jpg
magick identify -verbose input.jpg
magick identify -format "%wx%h" input.jpg
Batch Operations
Batch Resize
Using mogrify (in-place modification):
magick mogrify -resize 800x *.jpg
mkdir resized
magick mogrify -path resized -resize 800x *.jpg
Using loop (safer):
mkdir output
for img in *.jpg; do
magick convert "$img" -resize 800x "output/$img"
done
mkdir output
Get-ChildItem *.jpg | ForEach-Object {
magick convert $_.Name -resize 800x "output/$($_.Name)"
}
Batch Convert Format
for file in *.png; do
magick convert "$file" -quality 90 "${file%.png}.jpg"
done
for file in *.jpg; do
magick convert "$file" -quality 90 "${file%.jpg}.webp"
done
Batch Optimize
mkdir originals
for img in *.jpg; do
cp "$img" "originals/$img"
magick convert "$img" -strip -quality 85 "$img"
done
Parallel Processing
ls *.jpg | parallel magick convert {} -resize 800x output/{}
ls *.jpg | xargs -P 4 -I {} magick convert {} -resize 800x output/{}
Advanced Operations
Watermarking
magick convert input.jpg \
-gravity southeast \
-pointsize 24 \
-fill white \
-annotate +10+10 'Copyright 2025' \
output.jpg
magick convert input.jpg watermark.png \
-gravity southeast \
-geometry +10+10 \
-composite \
output.jpg
Image Composition
magick convert img1.jpg img2.jpg +append output.jpg
magick convert img1.jpg img2.jpg -append output.jpg
magick montage *.jpg -tile 3x3 -geometry +5+5 grid.jpg
Effects and Filters
magick convert input.jpg -colorspace Gray output.jpg
magick convert input.jpg -blur 0x8 output.jpg
magick convert input.jpg -sharpen 0x1 output.jpg
magick convert input.jpg -rotate 90 output.jpg
magick convert input.jpg -flip output.jpg
magick convert input.jpg -flop output.jpg
magick convert input.jpg -sepia-tone 80% output.jpg
Background Removal
magick convert input.jpg -fuzz 10% -transparent white output.png
magick convert input.jpg -fuzz 10% -fill blue -opaque white output.jpg
Useful Patterns
Create Thumbnails with Prefix/Suffix
for img in *.jpg; do
magick convert "$img" -resize 200x200 "${img%.jpg}_thumb.jpg"
done
for img in *.jpg; do
magick convert "$img" -resize 200x200 "thumb_$img"
done
Maintain Directory Structure
find . -name "*.jpg" -type f | while read file; do
dir=$(dirname "$file")
name=$(basename "$file")
mkdir -p "output/$dir"
magick convert "$file" -resize 800x "output/$dir/$name"
done
Progressive Quality Outputs
for quality in 95 85 75 60; do
magick convert input.jpg -quality $quality "output_q${quality}.jpg"
done
Generate Responsive Image Sizes
for width in 320 640 768 1024 1920; do
magick convert input.jpg -resize ${width}x "responsive/image_${width}w.jpg"
done
Error Handling and Validation
Check File Exists
if [ -f "input.jpg" ]; then
magick convert input.jpg -resize 800x output.jpg
else
echo "Error: input.jpg not found"
fi
Verify Output Created
magick convert input.jpg -resize 800x output.jpg
if [ -f "output.jpg" ]; then
echo "Success: output.jpg created"
else
echo "Error: conversion failed"
fi
Handle Spaces in Filenames
for img in *.jpg; do
magick convert "$img" -resize 800x "output/$img"
done
Format-Specific Options
JPEG
-quality 85
-sampling-factor 4:2:0
-interlace Plane
-strip
PNG
-quality 95
-depth 8
-alpha off
WebP
-quality 90
-define webp:lossless=true
Common Use Cases
Prepare Images for Web
magick convert input.jpg \
-resize 1920x \
-strip \
-quality 85 \
-sampling-factor 4:2:0 \
-interlace Plane \
output.jpg
Convert Screenshots to Optimized Format
for png in *.png; do
magick convert "$png" -strip -quality 90 "${png%.png}.jpg"
done
Create Social Media Images
magick convert input.jpg \
-resize 1200x630^ \
-gravity center \
-extent 1200x630 \
social_cover.jpg
magick convert input.jpg \
-resize 1080x1080^ \
-gravity center \
-extent 1080x1080 \
instagram.jpg
Troubleshooting
ImageMagick Not Found
magick --version
convert --version
Permission Denied
ls -l input.jpg
chmod 644 input.jpg
Out of Memory
magick convert input.jpg -limit memory 1GB -resize 800x output.jpg
Policy Errors (PDF, etc.)
Command Reference
Core Commands
magick convert - Convert and modify images
magick identify - Display image information
magick mogrify - Modify images in place
magick montage - Create composite images
magick compare - Compare two images
Legacy Commands (ImageMagick 6)
convert - Same as magick convert
identify - Same as magick identify
mogrify - Same as magick mogrify
montage - Same as magick montage
compare - Same as magick compare
Best Practices
- Always backup originals before batch operations
- Use descriptive output names to avoid confusion
- Quote filenames to handle spaces and special characters
- Test commands on single file before batch processing
- Create output directories before processing
- Use appropriate quality settings (85 is usually good for JPEGs)
- Strip metadata to reduce file size (unless needed)
- Maintain aspect ratio unless explicitly distorting
- Use modern syntax (
magick convert) for future compatibility
- Check command success before continuing in scripts