How to batch convert JPG to PNG files

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

Hello, friends. In this post, you will learn how to batch convert JPG to PNG files. The process is simple, but believe me, many times it can save you.

Imagine you have many JPG files and, for whatever reason, you need to convert them to PNG. The first thing you would think is to use an online service that allows you to do it, but the reality is that many of them, although free, do not allow you to do it in volume.

So, what to do? Is there a program for that? Of course, understand that we are not necessarily talking about 5 or 6 images, but it could be a lot.

Fortunately, on Linux we have a way to do it and the best way to do it is using the terminal, so we can use it in many configurations or scripts.

How to batch convert JPG to PNG files

The first thing to do is to install ImageMagick on your Linux distribution. In the case of Ubuntu 22.04 you can follow this post where we explain it in detail.

In the case of Debian and derivatives, you can also resort to the official repositories,

sudo apt update
sudo apt install imagemagick

But in distributions like Arch Linux, Manjaro or Parabola, you can run

sudo pacman -S imagemagick hostscript libheif libjxl libraw librsvg libwebp libwmf libxml2 libzip ocl-icd openexr openjpeg2 djvulibre pango potrace

By installing ImageMagick, you will have at your disposal a command called convert with which you can convert one file at a time. But as I said before, if you have many files it is no good to run it once and iterating is not convenient either.

However when you install ImageMagick you can also use the mogrify command which allows you to perform tasks such as converting photos to other formats or resizing images.

In this case, we will use it to batch convert images from JPG to PNG. To achieve this, you can run the following command.

mogrify -format png *.jpeg

This command will overwrite the files to JPG. You may want to back up the original files in case you are not happy with the changes.

You can also use it to resize them.

mogrify -resize 50% -format png *.jpeg

See, it’s effortless thanks to Linux and its terminal tools.

Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"
Angelo
Angelo
I am Angelo. A systems engineer passionate about Linux and all open-source software. Although here I'm just another member of the family.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

Join us on Facebook