Home » Questions » Computers [ Ask a new question ]

Batch converting PNG to JPG in linux

Batch converting PNG to JPG in linux

Does anyone know a good way to batch-convert a bunch of PNGs into JPGs in linux? (I'm using Ubuntu).

Asked by: Guest | Views: 379
Total answers/comments: 5
Guest [Entry]

"Your best bet would be to use ImageMagick.

I am not an expert in the actual usage, but I know you can pretty much do anything image-related with this!

An example is:

convert image.png image.jpg

which will keep the original as well as creating the converted image.

As for batch conversion, I think you need to use the Mogrify tool which is part of ImageMagick.

Keep in mind that this overwrites the old images.

The command is:

mogrify -format jpg *.png"
Guest [Entry]

"The convert command found on many Linux distributions is installed as part of the ImageMagick suite. Here's the bash code to run convert on all PNG files in a directory and avoid that double extension problem:

for img in *.png; do
filename=${img%.*}
convert ""$filename.png"" ""$filename.jpg""
done"
Guest [Entry]

find . -name "*.png" -print0 | xargs -0 mogrify -format jpg -quality 50
Guest [Entry]

"my quick solution
for i in $(ls | grep .png); do convert $i $(echo $i.jpg | sed s/.png//g); done"
Guest [Entry]

"Many years too late, there's a png2jpeg utility specifically for this purpose, which I authored.

Adapting the code by @Marcin:

#!/bin/sh

for img in *.png
do
filename=${img%.*}
png2jpeg -q 95 -o ""$filename.jpg"" ""$filename.png""
done"