How to Convert PNG to JPG on Ubuntu via Command

Last updated: April 21, 2024

This simple tutorial will show you how to convert PNG to JPG in Ubuntu, so that it reduce the memory size and speed up loading image time.

1.) Install the required package by running below command in terminal:

sudo apt-get install imagemagick

2.) Then you can convert an .png image to .jpg format via below command. It takes “ubuntuhandbook.png” in the current directory and creates a JPEG image from it.

convert ubuntuhandbook.png ubuntuhandbook.jpg

You can also specify a compression level for JPEG images.

convert ubuntuhandbook.png -quality 90 ubuntuhandbook.jpg

3.) If you want to convert a batch of photo images, for example all .png files in “Pictures” folder, use try this command instead:

cd ~/Pictures && for file in *.png; do convert $file ${file%.png}.jpg; done

4.) To convert all PNG files into JPEG files with that same filename but a different suffix. However be warned that if existing file with the same name will be over-written.

mogrify -format jpg *.png

Twitter

I'm a freelance blogger who started using Ubuntu in 2007 and wishes to share my experiences and some useful tips with Ubuntu beginners and lovers. Please comment to let me know if the tutorial is outdated! And, notify me if you find any typo/grammar/language mistakes. English is not my native language. Contact me via ubuntuhandbook1@gmail.com Buy me a coffee: https://ko-fi.com/ubuntuhandbook1 |

2 responses to How to Convert PNG to JPG on Ubuntu via Command

  1. How!!??? I paste in the all command and get this stupid error:

    mogrify: unable to open file `boot.png’ @ error/png.c/ReadPNGImage/3922.

    • I got the same error. Make sure that you are in the same directory as the images that you want to convert.
      It works like a charm to me.