ImageMagick Snippets @ r1

Contents hide

Make image square

This will add padding to make an image perfectly square. Change -gravity option to not put the image in the center.

bash
magick input.png -gravity center -thumbnail 400x400^ -background transparent -extent 400x400 -strip output.png

Properly scale pixel art

By default, resizing an image using ImageMagick will do some kind of intelligent interpolation to get the new color value of each pixel (i.e. antialiasing). Normally, this is what you want. For pixel art, however, you absolutely don't want that. If each "pixel" in the image maps to a 4x4 pixel on the screen, and you resize it by half, you would expect each new "pixel" to be a 2x2 pixel on the screen. Due to the default interpolation filters in ImageMagick, that doesn't happen, and you get "smudgy" pixels that bleed into each other instead of sharp pixels, like you would expect in pixel art.

By setting the -filter option to point, this will do no longer do fancy math to generate the new color for each pixel.

bash
magick input.png -filter point -resize x480 -strip output.png