Does anyone know a good way to batch-convert a bunch of PNGs into JPGs in linux? (I'm using Ubuntu).
A png2jpg binary that I could just drop into a shell script would be ideal.
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:
and it will keep the original as well as creating the converted image. As for batch. I think you need to use the Mogrify tool (from the same command line when in imagemagick). Keep in mind that this overwrites the old images.
The command is:
I have a couple more solutions.
The simplest solution is like most already posted. A simple bash for loop.
For some reason I tend to avoid loops in bash so here is a more unixy xargs approach, using bash for the name-mangling.
The one I use. It uses GNU Parallel to run multiple jobs at once, giving you a performance boost. It is installed by default on many systems and is almost definitely in your repo (it is a good program to have around).
The number of jobs defaults to the number of processes you have. I found better CPU usage using 3 jobs on my dual-core system.
And if you want some stats (an ETA, jobs completed, average time per job...)
There is also an alternative syntax if you are using GNU Parallel.
And a similar syntax for some other versions (including debian).
The actual "
my quick solution
For batch processing:
You will end up with file names like image1.png.jpg though.
This will work in bash, and maybe bourne. I don't know about other shells, but the only difference would likely be the loop syntax.
For those who just want the simplest commands:
Convert and keep original files:
Convert and remove original files:
Batch Converting Explained
Kinda late to the party, but just to clear up all of the confusion for someone who may not be very comfortable with cli, here's a super dumbed-down reference and explanation.
Keeps all original png files as well as creates jpg files.
Convert and Remove
Converts all png files to jpg, removes original.
Now here's some goodies for the people who are comfortable with the cli.
If you want some output while it's converting files:
Convert all png files in all subdirectories and give output for each one:
Convert all png files in all subdirectories, put all of the resulting jpgs into the