Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ImageMagick Tricks

ImageMagick Tricks

Cutting Up Tiles

convert image.png -crop 128x128 +repage +adjoin tile-%d.png

Autocrop Empty Space

http://www.imagemagick.org/script/command-line-options.php#trim

Uses the top-left pixel colour:

convert image.png -trim +repage result.png

+repage removes offset metadata from result.

With fuzzy colour match:

convert image -fuzz 1% -trim +repage result

Colours are messed up!

Usually because the image uses a colour profile which isn't supported on some programs and web browsers. Use -strip to apply and remove color profiles.

Gradient Fade an image using a transparent -> black mask

First, create a mask image where it goes from transparent to black. Then run:

convert -compose Dst_In -gravity center  ./adenine.png ../mugshot-mask.png -composite adenine-new.png

Circle Crop

# source = 84 output = 66, radius = 33
convert input.png -crop 66x66+9+9 +repage \( +clone -fill Black -colorize 100 -fill White -draw 'circle 33,33 33,0' \) -alpha off -compose CopyOpacity -composite output.png

Centre an image to a square canvas without resizing

Note the sub command.

convert image.png -gravity center -background transparent -extent `identify -format "%[fx:max(w,h)]x%[fx:max(w,h)]+0+0" image.png` +repage out.png
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment