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.
|
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
|
|||||||||||||||||
|
|
The actual "
|
||||
|
|
tl;drFor those who just want the simplest commands: Convert and keep original files:
Convert and remove original files:
Batch Converting ExplainedKinda 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. Example Directory
Simple ConvertKeeps all original png files as well as creates jpg files.
Result
Explanation
Convert and RemoveConverts all png files to jpg, removes original.
Result
Explanation
Fancy StuffNow 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
|
|||||||||||||||||||||
|
|
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. |
|||
|
|
|
Many years too late, there's a png2jpeg utility specifically for this purpose, which I authored. Adapting the code by @Marcin:
|
||||
|
|
|
This is what I use to convert when the files span more than one directory. My original one was TGA to PNG
The concept is you
|
|||
|
|