All Posts programming magick cheat-sheet

magick cheat-sheet

ยท 749 words ยท 4 minute read

magick ๐Ÿ”—

Create, edit, compose, or convert between image formats. This tool replaces convert in ImageMagick 7+.

See magick convert to use the old tool in versions 7+. (below)

More information: https://imagemagick.org .

Convert between image formats:

magick path/to/input_image.png path/to/output_image.jpg

Resize an image, making a new copy:

magick path/to/input_image.jpg -resize 100x100 path/to/output_image.jpg

Create a GIF out of all JPEG images in the current directory:

magick *.jpg path/to/images.gif

Create a checkerboard pattern:

magick -size 640x480 pattern:checkerboard path/to/checkerboard.png

Create a PDF file out of all JPEG images in the current directory:

magick *.jpg -adjoin path/to/file.pdf

magick montage ๐Ÿ”—

Tile images into a customizable grid.

More information: https://imagemagick.org/script/montage.php .

Tile images into a grid, automatically resizing images larger than the grid cell size:

magick montage path/to/image1.jpg path/to/image2.jpg ... path/to/montage.jpg

Tile images into a grid, automatically calculating the grid cell size from the largest image:

magick montage path/to/image1.jpg path/to/image2.jpg ... -geometry +0+0 path/to/montage.jpg

Specify the grid cell size and resize images to fit it before tiling:

magick montage path/to/image1.jpg path/to/image2.jpg ... -geometry 640x480+0+0 path/to/montage.jpg

Limit the number of rows and columns in the grid, causing input images to overflow into multiple output montages:

magick montage path/to/image1.jpg path/to/image2.jpg ... -geometry +0+0 -tile 2x3 montage_%d.jpg

Resize and crop images to fill their grid cells before tiling:

magick montage path/to/image1.jpg path/to/image2.jpg ... -geometry +0+0 -resize 640x480^ -gravity center -crop 640x480+0+0 path/to/montage.jpg

magick mogrify ๐Ÿ”—

Perform operations on multiple images, such as resizing, cropping, flipping, and adding effects. Changes are applied directly to the original file.

More information: https://imagemagick.org/script/mogrify.php .

Resize all JPEG images in the directory to 50% of their initial size:

magick mogrify -resize 50% *.jpg

Resize all images starting with DSC to 800x600:

magick mogrify -resize 800x600 DSC*

Convert all PNGs in the directory to JPEG:

magick mogrify -format jpg *.png

Halve the saturation of all image files in the current directory:

magick mogrify -modulate 100,50 *

Double the brightness of all image files in the current directory:

magick mogrify -modulate 200 *

Reduce file sizes of all GIF images in the current directory by reducing quality:

magick mogrify -layers 'optimize' -fuzz 7% *.gif

Display help:

magick mogrify -help

magick import ๐Ÿ”—

Capture some or all of an X server screen and save the image to a file.

More information: https://imagemagick.org/script/import.php .

Capture the entire X server screen into a PostScript file:

magick import -window root path/to/output.ps

Capture contents of a remote X server screen into a PNG image:

magick import -window root -display remote_host:screen.display path/to/output.png

Capture a specific window given its ID as displayed by xwininfo into a JPEG image:

magick import -window window_id path/to/output.jpg

magick identify ๐Ÿ”—

Describe the format and characteristics of image files.

More information: https://imagemagick.org/script/identify.php .

Describe the format and basic characteristics of an image:

magick identify path/to/image

Describe the format and verbose characteristics of an image:

magick identify -verbose path/to/image

Collect dimensions of all JPEG files in the current directory and save them into a CSV file:

magick identify -format "%f,%w,%h\n" *.jpg > path/to/filelist.csv

magick convert ๐Ÿ”—

Convert between image formats, scale, join, and create images, and much more.

Note: this tool (previously convert) has been replaced by magick in ImageMagick 7+.

More information: https://imagemagick.org/script/convert.php .

Convert an image from JPEG to PNG:

magick convert path/to/input_image.jpg path/to/output_image.png

Scale an image to 50% of its original size:

magick convert path/to/input_image.png -resize 50% path/to/output_image.png

Scale an image keeping the original aspect ratio to a maximum dimension of 640x480:

magick convert path/to/input_image.png -resize 640x480 path/to/output_image.png

Scale an image to have a specified file size:

magick convert path/to/input_image.png -define jpeg:extent=512kb path/to/output_image.jpg

Vertically/horizontally append images:

magick convert path/to/image1.png path/to/image2.png ... -append|+append path/to/output_image.png

Create a GIF from a series of images with 100ms delay between them:

magick convert path/to/image1.png path/to/image2.png ... -delay 10 path/to/animation.gif

Create an image with nothing but a solid red background:

magick convert -size 800x600 "xc:#ff0000" path/to/image.png

Create a favicon from several images of different sizes:

magick convert path/to/image1.png path/to/image2.png ... path/to/favicon.ico

magick compare ๐Ÿ”—

Create a comparison image to visually annotate the difference between two images.

Compare two images:

magick compare path/to/image1.png path/to/image2.png path/to/diff.png

Compare two images using the specified metric:

magick compare -verbose -metric PSNR path/to/image1.png path/to/image2.png path/to/diff.png

See also: magick. More information: https://imagemagick.org/script/compare.php .

I hope you enjoyed reading this post as much as I enjoyed writing it. If you know a person who can benefit from this information, send them a link of this post. If you want to get notified about new posts, follow me on YouTube , Twitter (x) , LinkedIn , and GitHub .