. : December 30, 2015 : .
Batch Process Images Using a Shell Script
TweetA while back, I wrote about batch processing images with Pixelmator. That works great if you don’t need to change the resolution of the images. If you need to change the resolution of the images, and you are Photoshop free [like me], you can batch process images using a shell script.
sips
The Mac operating system ships with a command line program called sips (scriptable image processing system). Unfortunately, as many people discovered long before I ever attempted this, there is a bug. It doesn’t change the resolution, unless you change the format of the image as well. If you need to change formats anyway, like if you are resizing TIFFs for a website, and you are changing them to JPEGs, you have nothing to worry about. Otherwise, you might be slightly annoyed at this bug, like me.
Workaround
Simple: change it to a different format while changing the resolution, and then change it back again. Yes, I know this is stupid, but it works. Below is a shell script I wrote to do it. It replaces the original images with the processed ones, so copy them before using it.
My shell script
#!/bin/bash IMAGES=/path/to/a/directory/with/all/your/images/that/you/want/to/resize/* for f in $IMAGES do # -Z 1500: resize height and width proportionally to < 1500 px # -s dpiHeight 72.0 -s dpiWidth 72.0: change resolution to 72 dpi # -s format tiff -s formatOptions high: change it to a TIFF file # --out sipsIsBuggyAndItMakesMeMadButItsStillBetterThanBuyingPhotoshopFromAdobeSoSuckItUpAndStopWhining.tif sips -s format tiff -s formatOptions high $f -s dpiHeight 72.0 -s dpiWidth 72.0 -Z 1500 --out sipsIsKindOfBuggyButItsBetterThanBuyingPhotoshopSoSuckItUpAndStopWhining.tif # change it back to JPEG format sips -s format jpeg -s formatOptions normal sipsIsKindOfBuggyButItsBetterThanBuyingPhotoshopSoSuckItUpAndStopWhining.tif --out $f done
Conclusion
For the most part, sips is great. I just wish I didn’t have to use this workaround. Here’s the man page for it. It is quite a useful tool.
References:
- sips not setting dpi to 72 of jpg images
- anybody use sips to change image dpi?
- sips not setting dpi to 72 of jpg images
- sips(1) Mac OS X Manual Page
Categories:
One response to “Batch Process Images Using a Shell Script”
Leave a Reply
You must be logged in to post a comment.
[…] tool seem to have a bug that will not convert the DPI if the format is JPEG. So you may need to use a workaround or modify the script to output a different format from the input […]