Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert all files (in different formats) in given folder to different file type

I have a folder with many images from different types (png, jpg, jpeg, bmp, pdf), and I would like to convert them all into png (for instance) using imagemagick.

Is there a single command which can perform this? If not, what should I do instead?

Thanks.

like image 926
Tal Galili Avatar asked Mar 09 '13 20:03

Tal Galili


2 Answers

Try the mogrify command:

mogrify -format png *.* 

But be careful. Without the -format option, mogrify overwrites the original images. Make sure to read the documentation.

like image 158
nwellnhof Avatar answered Sep 22 '22 06:09

nwellnhof


Although mogrify seems to do the job, I would like to show you how this can be done with multiple commands with convert from ImageMagick.

I think multiple commands are better, because the number of file types is supposedly quite small and you can better adjust it to your needs:

This command:

for file in *.xbm; do convert $file "`basename $file .xbm`.png"; done 

will convert all .xbm files to .png while not touching the xbm files.

Then you can move all "converted" files:

mkdir converted for file in *.xbm; do mv $file converted/; done 
like image 45
Martin Thoma Avatar answered Sep 26 '22 06:09

Martin Thoma