Tal Galili
Tal Galili

Reputation: 25376

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.

Upvotes: 47

Views: 79508

Answers (3)

kenorb
kenorb

Reputation: 166919

You can use convert command from ImageMagick package, e.g.

find . -maxdepth 1 \( -iname \*.png -o -iname \*.jpg -o -iname \*.jpeg -o -iname \*.bmp -o -iname \*.pdf \) -exec convert -verbose "{}" "DEST_DIR/{}.png" \;

Or if you've got all the files in the same directory, try the following simpler way:

convert '*.*' converted_%04d.png

Similar: How can I scale all images in a folder to the same width?

Upvotes: 6

nwellnhof
nwellnhof

Reputation: 33658

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.

Upvotes: 87

Martin Thoma
Martin Thoma

Reputation: 136865

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

Upvotes: 41

Related Questions