Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

How to save image in different format

📅 2016-May-30 ⬩ ✍️ Ashwin Nanjappa ⬩ 📚 Archive

A common operation when working with images is to save them in a different format. Not surprisingly, ImageMagick has tools that make this very easy to perform at the shell.

The easiest way to save an image in a different format is to use convert:

$ convert foo.png bar.jpg

This saves an existing foo.png in PNG format to another file bar.jpg in the JPEG format.

Note that this command does not work if you want to convert a set of images. To do that, we use the mogrify command with its -format option.

To convert all PNG images in the current directory to JPEG format images keeping the same filename:

$ mogrify -format "jpg" *.png

Mogrify usually overwrites its source files. In this case however, the original PNG files are left untouched since the new files have a different file extension.

Tried with: ImageMagick 6.7.7 and Ubuntu 14.04