<- Back

imagemagick

Image modification
Downscale
magick mogrify -auto-orient -strip -resize "1920x1920>" -quality 85 *.jpg
Remove first pixel row
magick convert input.png -chop 0x1 output.png
Convert to webp
magick convert -auto-orient -strip -resize "600x600>" -quality 75 -define webp:method=6 -define webp:use-sharp-yuv=1 image.jpg image.webp
Batch processing
for i in *.jpg; do magick convert /* your options */ $i ${i/.jpg/.webp}; done
Preserve timestamp
magick mogrify -define preserve-timestamp=true <filename.jpg>
Iterate big files
find . \( -iname "*.jpg" -o -iname "*.jpeg" \) -type f -size +1500k -exec magick mogrify [...] {} \;
Crop from center
magick convert -gravity Center -crop 240x240+0+0 input.jpg output.jpg
Image information
Quality of jpeg
magick identify -format '%Q' <filename.jpg>
Exif tags and general info
magick identify -verbose input.jpg
Signature hash of image (pixels only, metadata is ignored, see links below)
magick identify -format %# input.jpg
Animation
Create gif
magick convert -delay 30 -loop 0 -resize 50% *.jpg animation.gif
Color reduction
Reduce colors
magick convert input.png +dither -colors 16 output.png
Posterize
magick convert input.png -posterize 8 output.png
Diff image
Show differences in red
magick compare image1.png image2.png -compose src diff.png
Subtract image
magick composite image1.png image2.png -compose difference diff.png
PDF
Convert images to pdf
magick convert *.jpg -auto-orient -background white -units pixelsperinch -density 72 -page a4 output.pdf
Favicon
Convert .svg to .ico
magick -density 256x256 -background transparent favicon.svg -define icon:auto-resize -colors 256 favicon.ico
Specify sizes
-define icon:auto-resize=16,24,32,64
Convert .svg to .png
magick -density 128x128 -background transparent favicon.svg -resize 192x192 favicon.png
Check generated .ico file
icotool --list favicon.ico
Reduce size of svg or png
optipng
optipng image.png
pngquant (lossy)
pngquant image.png
svgo
svgo image.svg -o image.min.svg

See here: https://imagemagick.org/script/command-line-options.php#format_identify_

and here: https://imagemagick.org/script/escape.php