[info] Bulk image conversion

rado84

Well-Known Member
Joined
Feb 25, 2019
Messages
880
Reaction score
724
Credits
5,997
Probably all of us have been in a situation where we had to convert more than a few images to one format or the other for whatever reason. Converting them manually with a GUI program can quickly become tedious and once again I found myself in such a situation. So I decided to look for a CLI solution and finally found one: a tool named cwebp, which is part of the package libwebp (that's the package name in Arch repo but it could differ for your distro). Libwebp is a mandatory dependency for ffmpeg, ffmpeg4.4, gimp, qt5-imageformats, qt6-imageformats, qt6-webengine, thunderbird and many others, so if you have any of these packages installed, then it's highly likely that you also have libwebp installed. Despite its name, "cwebp" (stands for "convert webp") can convert to and from webp, as well as PNG-JPG two-way.

I wrote a few scripts (by "trial and error", until I discovered exactly how the tool works and a little help from an AI) for the most frequently used formats on the internet, including on YouTube when you upload a video (YT requres JPG image no larger than 1 MB). This tool is doing the job perfectly, so I decided to share these scripts in case you too need them:

Bulk JPG to PNG:
Code:
#!/bin/bash

for file in *.jpg;
do cwebp -q 100 "$file" -o "${file/.jpg/}.png";
done

Bulk PNG to JPG:
Code:
#!/bin/bash

for file in *.png;
do cwebp -q 100 "$file" -o "${file/.png/}.jpg";
done

Bulk PNG to WEBP:
Code:
#!/bin/bash

for file in *.png;
do cwebp -q 100 "$file" -o "${file/.png/}.webp";
done

Ofc there can be other combinations but since I need to use these most frequently, I wrote scripts only for them. You can rewrite them for whatever format range you want, just keep in mind that animated images (GIF) are not supported.
 


If you need a GUI way to do this, XNViewMP does batch processing and is pretty easy to understand.

They even have a dedicated application for this, but you don't need it. You can just use the main program.
 
I haven't used it for format conversions, though I know it has those options, but I've used imagemagick to do scripted bulk processing (mostly scaling) on images. It was pretty straight forward - "learning curve" was basically non-existent.
 


Members online


Latest posts

Top