Home Linux Commands How to Batch Convert PNG Images to JPG Format in Linux

How to Batch Convert PNG Images to JPG Format in Linux

Although PNG offers a better image quality compared with JPG, the large size factor is usually a concern for Internet users. This is typically why PNG images are converted to JPG.

In this article, you will learn how to convert multiple PNG images to JPG format from the Linux command line. We will use 2 tools, namely; ImageMagick and GraphicsMagick.

Install Imagemagick in Linux

ImageMagick is a free tool for creating, modifying, and converting a wide variety of image file formats including PNG. To install ImageMagick on your Linux machine, run the following command as per your Linux distribution.

$ sudo apt install imagemagick   [On Debian/Ubuntu & Mint]
$ sudo dnf install ImageMagick   [On RHEL/CentOS & Fedora]

Batch Convert PNG to JPG with ImageMagick

First, change into the directory containing the PNG files with the cd command. After that, you may use the command below to list the content of the directory.

$ ls -lh

Next, run the command below to convert all PNG files in the current directory to JPG.

$ mogrify -format jpg *.png 

Now, run the command below again to see the results.

$ ls -lh
Convert PNG to JPG with ImageMagick
Convert PNG to JPG with ImageMagick

Looking at the file size column in the image above, the difference is clear. As a side note, you can convert a single file as follows.

$ convert file.png file.jpg

Feel free to read the manual pages and discover what more you could do with the ImageMagick tool.

$ man imagemagick

Install GraphicsMagick in Linux

GraphicsMagick was derived from ImageMagick but it offers faster processing and better quality. To install GraphicsMagick on your Linux machine, run the following command as per your Linux distribution.

$ sudo apt install graphicsmagick   [On Debian/Ubuntu & Mint]

$ sudo yum install epel-release     [On RHEL/CentOS]
$ sudo dnf install GraphicsMagick   [On RHEL/CentOS & Fedora]

Batch Convert PNG to JPG with GraphicsMagick

Begin by changing into the directory containing the PNG files and then run the command below to list the content of the directory.

$ ls -lh

Now, to convert all PNG files in the current directory to JPG format, run the following command.

$ sudo gm mogrify -format jpeg *.png

And check the results with the following command.

$ ls -lh
Convert PNG to JPG with GraphicsMagick
Convert PNG to JPG with GraphicsMagick

If you would like to convert a specific file from PNG to JPEG, you can run the command below.

$ gm convert file.png file.jpeg

To find out what more you can do with the GraphicsMagick tool, run the command below to view the manual pages.

$ man gm
Conclusion

We have shown you how to convert multiple PNG files into JPG format in this guide. While doing this can save you some network bandwidth and storage space, the image quality will be affected.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.