Resize image with Automator/SIPS

Dimwhit

macrumors 68000
Original poster
Apr 10, 2007
1,980
174
I just can't figure this out. I've found a lot of stuff online about batch converting with sips and automator, but I just can't get any of it to work. I also don't want to batch convert.

Here's what I'm trying to do:

right-click on an image
select a resize service
resize image to 450px wide, 72dpi (usually from 300dpi), and set a jpg quality to 80

So I created a new service. The first step is to Copy Finder Item and put it on the desktop.

From there, I want to Run Shell Script. Right? I just can't get a script to work using sips (or anything else that will do it).

Anyone have an idea how to do this? I tried some short tests. Did this one (that I found online):

Code:
#bin/bash

for f in "$@"
do
     /usr/bin/sips -s dpiHeight 72.0 -s dpiWidth 72.0 $f

done
Nothing. Didn't change the resolution. I've tried others that resize the file and set a compression level, but I can't get them to work. Any thoughts, or a script I can trigger with Automator?
 

w0lf

macrumors 65816
Feb 16, 2013
1,233
75
USA
Never used sips before but it could be that the $f needs quotes. For example if your file was:

/Users/some person/Desktop/really cool image.jpg

that would come out as:

Code:
/usr/bin/sips -s dpiHeight 72.0 -s dpiWidth 72.0 /Users/some
person/Desktop/really
cool
image.jpg
rather than:
Code:
/usr/bin/sips -s dpiHeight 72.0 -s dpiWidth 72.0 "/Users/someperson/Desktop/really cool image.jpg"
Other potential issue I suppose is you might not be able to make multiple changes in one line.

So something like
Code:
/usr/bin/sips -s dpiHeight 72.0 -s dpiWidth 72.0 "$f"
Might be different than
Code:
/usr/bin/sips -s dpiHeight 72.0 "$f"
/usr/bin/sips -s dpiWidth 72.0 "$f"
You might also need to specify a output file as I'm not really sure how it works
Code:
#remove extension and add modified.jpg
name=${f%.*}" modified.jpg"
#edit and output as $name
/usr/bin/sips -s dpiHeight 72.0 -s dpiWidth 72.0  "$f" "$name"
You might even be able to use the same input file as the output file
Code:
/usr/bin/sips -s dpiHeight 72.0 -s dpiWidth 72.0  "$f" "$f"
 

Dimwhit

macrumors 68000
Original poster
Apr 10, 2007
1,980
174
Thanks. I was able to get almost everything to work. Except changing the resolution. Seems to be a common issue with jpg files, but I haven't found anything that actually works.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.