Macos – How to convert GIF files to PNG or JPEG in OS X with command line

conversionjpegmacospng

I have 10k+ GIF files that I need to convert to PNG or JPEG preferably using command line so that I can automate it. I'm not worried about losing quality or transparency, just need to prepare files for OCR software.

When trying to use convertformat, I get this:

Error in pixReadStreamGif: function not present
Error in pixReadStream: gif: no pix returned
Error in pixRead: pix not read
Error in pixGetDepth: pix not defined
Error in pixWrite: pix not defined

Any ideas?

Best Answer

No need for any additional tools. OS X has sips, which can convert images to (almost) any format.

For example, to convert every .gif to .jpeg, putting them into a folder called jpegs:

mkdir jpegs
sips -s format jpeg ./*.gif --out jpegs

Or, to recursively convert them using find, which will place a JPEG file with the same name as the GIF next to it.

find . -iname "*.gif" -type f -exec sh -c 'sips -s format jpeg "$0" --out "${0%.gif}.jpeg"' {} \;