Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Useful ImageMagick snippets
# Flatten a transparent image with a white background:
convert -flatten img1.png img1-white.png
# Make an image transparent
convert -transparent '#FFFFFF' nontransparent.gif transparent.png
# convert an image into tiles
convert -size 3200x3200 tile:single_tile.png final.png
# making a montage from a collection of images
montage -geometry +0+0 -background transparent *png montage.png
# inverting colors
convert before.png -negate after.png
# generating a favicon
convert large_image.png -resize 16x16! favicon.ico
# adding numbers to a tiled image
cmd = (0..324).to_a.inject([]) do |cmd,n|
y=(n/25*32)+15; x=((n%25)*32)+15
cmd << "-draw 'fill red text #{x},#{y} \"#{n}\"'"
`convert img.png #{cmd.join(' ')} annotated_img.png`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment