How to Pixelate an Image with ImageMagick Convert?
This article provides a quick overview and a step-by-step guide on
how to pixelate an image using the ImageMagick convert
command. Pixelation is a popular effect used to censor sensitive
information or create retro pixel art, and it can be achieved
efficiently in the command line by downscaling an image and then scaling
it back up to its original size. Below, you will find the exact command
structure, an explanation of how the parameters work, and examples for
adjusting the pixel block size.
To pixelate an image using ImageMagick, you need to resize the image
to a much smaller percentage of its original size and then scale it back
up using the -scale option. The -scale option
is crucial because it uses a nearest-neighbor interpolation method,
which preserves the blocky, pixelated edges rather than smoothing them
out.
The Standard Pixelation Command
Here is the fundamental command to achieve the pixelation effect:
convert input.jpg -scale 10% -scale 1000% output.jpg
How the Parameters Work
convert input.jpg: This specifies the input image file you want to modify.-scale 10%: This shrinks the image down to 10% of its original dimensions, throwing away a massive amount of pixel detail.-scale 1000%: This blows the shrunken image back up to 1000% of its new size, which restores it exactly to its original dimensions. Because ImageMagick doesn’t try to blend or blur the pixels during a-scaleoperation, you get distinct, sharp blocks.output.jpg: This is the name of the newly created pixelated image.
Adjusting the Intensity of the Pixelation
You can control how large or small the pixel blocks are by changing the percentages. The key is to ensure that the second percentage reverses the math of the first percentage so your final image size doesn’t change.
- For larger, heavier blocks (More Censorship):
Shrink it further, then scale it back up higher.
convert input.jpg -scale 5% -scale 2000% output.jpg - For smaller, subtler blocks (Less Censorship):
Shrink it less, then scale it back up less.
convert input.jpg -scale 25% -scale 400% output.jpg