X

How to convert a PNG file to JPG on Ubuntu

JPEG is a lossy compression file format for digital images. It can greatly reduce the amount of storage space used by a graphics file compared to the PNG format. This tutorial describes how to convert a PNG file to JPG on the shell. I use the GraphicsMagick command-line tool on my Ubuntu 20.04 system to do this; the same steps work on Debian and probably on other Linux distributions. GraphicsMagick is an improved version of the well-known tool ImageMagick.

Install GraphicsMagick on Ubuntu

The first step is to install the Ubuntu GraphicsMagick package with apt:

sudo apt-get install graphicsmagick

Here the installation result:

Convert PNG file to JPG

Now we'll convert a PNG file to JPG. Here I use a file named street.png and the new file will be saved as street.jpg. The photo is stored in the directory where I execute the command.

gm convert street.png street.jpg

Here is how the command is executed on the Linux shell:

This reduces the file size from 649KB to 71KB.  Here the result of our image file format conversion:

Convert JPG file to PNG

The file format conversion works in the other way as well, here I'll convert the file street.jpg to street.png.

gm convert street.jpg street.png

GraphicsMagick supports many more file formats, not just PNG and JPEG, a full list can be found here: http://www.graphicsmagick.org/formats.html

Tags: Shell
Till Brehm:
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings