How to Convert JPG to PNG Using ImageMagick?

This article provides a quick, practical guide on how to convert images from JPG to PNG format using the ImageMagick convert command-line tool. You will learn the basic command syntax, how to handle batch conversions for multiple files, and how to apply useful quality adjustments during the conversion process.

The Basic Conversion Command

To convert a single JPG image to a PNG file, you need to open your terminal or command prompt and use the standard convert syntax. The tool automatically detects the desired output format based on the file extension you provide.

convert input.jpg output.png

In this command, input.jpg represents your original image, and output.png is the name of the new file that ImageMagick will create.

Batch Converting Multiple Files

If you have an entire directory of JPG files that you want to change to PNG, doing them one by one is inefficient. You can use a loop in your terminal to handle bulk conversions quickly.

For Linux and macOS (Bash):

for img in *.jpg; do
    convert "$img" "${img%.jpg}.png"
done

For Windows (Command Prompt):

for %i in (*.jpg) do convert "%i" "%~ni.png"

Advanced Options During Conversion

While a simple format change is often enough, ImageMagick allows you to modify the image properties during the conversion process.

convert input.jpg -alpha on output.png
convert input.jpg -quality 95 output.png

Note: For PNG files, the first digit of the -quality flag represents the compression level, while the second digit represents the filter type.

Verifying the Installation

If the convert command is not recognized by your system, ensure that ImageMagick is properly installed and added to your system’s environment variables. On newer versions of ImageMagick (v7 and above), the convert utility is often called directly via the main magick command:

magick input.jpg output.png