All imagemagick commands I ever needed

ImageMagick is a free and open-source software suite for image editing. It is my go-to command-line tool for converting, modifying, and editing images.

While your Adobe Creative Cloud Suite might be capable of doing all the same things, ImageMagick has all the benefits of a command-line tool, namely better reproducibility, and efficiency when converting lots of images. Did I mention that imagemagick is free?

Another advantage is ImageMagick’s unparalleled ability to read more than 100 image file formats and easily convert one into the other.

Below, I keep a running list of all commands I ever needed, so I don’t have to google them again.

Modifying single files

Reduce the quality of a jpg

convert big_image.jpg -strip -quality 90  small_image.jpg

Compress a pdf, resize it, and increase the contrast by stretching the range of intensity values

convert big_pdf.pdf -contrast-stretch 1x1% -resize 20% -compress Group4 small_pdf.pdf 

Crop a single image to a specific format. The format is -crop x_size x y_size + x_offset + y_offset.

convert input.png -crop 1900x1800+300+100  output.png

Processing multiple files

Crop multiple files. The format is -crop x_size x y_size + x_offset + y_offset.

mkdir cropped
mogrify -crop 1800x1700+300+100 -path ./cropped *.png

Convert all files in a directory to the same width and reformat to jpg

mkdir output
mogrify -path ./output -resize 180 -format jpg *.*

Convert all jpgs in a directory to same size, reduce their quality, and output as jpg.

mkdir output
mogrify -path ./output -resize 900 -quality 80 -format jpg *.jpg 

Reduce the quality of all jpgs in a directory

mogrify -quality 80% *.jpg

Leave a Reply

Your email address will not be published.