PNGifier

How to Convert a PNG with ImageMagick

ImageMagick is a free, cross-platform command-line tool for editing and converting images. This guide walks through converting PNG files with the modern magick command — changing formats, setting quality, exporting WebP, flattening transparency for JPG, and batch-converting whole folders with mogrify.

By Published

What is ImageMagick?

ImageMagick is a free, open-source command-line image tool that runs on Windows, macOS, and Linux. It reads and writes over a hundred formats, so it's a reliable way to convert and process images from a terminal. In ImageMagick 7 the main command is magick;older version 6 installs used convert instead, which still works but is deprecated.

Because it runs from the command line, ImageMagick is ideal for servers, build scripts, and automation where you want to convert images without opening an editor. For a quick one-off conversion without installing anything, a browser converter such as PNG to JPG works just as well.

How do you do a basic PNG conversion?

The simplest conversion just changes the file extension. ImageMagick reads the input format and writes whatever format the output name implies, so turning a PNG into a JPG is a single line:

magick input.png output.jpg

That command takes input.png and writes a new output.jpg next to it. The original PNG is left untouched. The same pattern works for any supported target, such as output.gif or output.tiff.

How do you set quality and convert to WebP?

For lossy formats you can control the trade-off between size and quality with the -quality option, where 100 is best and lower numbers make smaller files. To convert a PNG to WebP at quality 85:

magick input.png -quality 85 output.webp

WebP keeps the PNG's transparency, so this is a great way to shrink web images without losing a transparent background. If you'd rather not install ImageMagick, you can convert PNG to WebP in your browser instead.

How do you flatten transparency for JPG?

JPG has no transparency, so converting a PNG with a transparent background can leave odd black edges. The fix is to flatten the image onto a solid background color first — white is the usual choice:

magick input.png -background white -flatten output.jpg

The -background white option sets the fill color and -flatten merges the transparent areas onto it, giving you a clean JPG with a white background. Swap white for any color name or hex value to match your design.

How do you batch-convert a whole folder?

To convert many files at once, use mogrify, the batch-oriented companion to magick. With the -format option it converts every matching file and writes a new file for each, leaving the PNG originals in place:

mogrify -format jpg *.png

This turns every PNG in the current folder into a JPG of the same name. Combine it with the options above — for example -quality or -flatten — to apply the same settings across an entire directory in one command. If you only need to learn more about the source format first, see what is a PNG, or browse all the browser tools.

Frequently asked questions

What is the difference between magick and convert?
They do the same job. magick is the modern top-level command in ImageMagick 7, while convert was the command in version 6 and is now deprecated. Use magick if it is available.
Does ImageMagick keep PNG transparency when converting?
It depends on the target format. WebP keeps the alpha channel, so transparency survives. JPG has no transparency, so you should flatten the image onto a background color first to avoid odd black or white edges.
How do I convert many PNG files at once?
Use mogrify with the -format option, for example mogrify -format jpg *.png. It writes a new file next to each PNG instead of overwriting the originals.
Do I need to install anything to convert a single PNG?
Only if you want to use ImageMagick. For a quick one-off conversion you can use a browser-based converter instead and skip the install entirely.