Tuesday, May 20, 2014

OS X SIPS Command

It's better to pass command line args as an array than a string.
If you've ever needed to rotate, resize, or convert an image, programmatically, then take a look at the OS X SIPS command. SIPS is a highly optimized part of Core Graphics (Quartz) designed for the Automator app. It's been around for nearly a decade (Tiger 10.4). I first heard about it when chatting with another Apple engineer who was developing it in Cupertino.

Since Java's early days I have been manipulating images inside of web apps. In the 1990s, Java image manipulation was very crude and slow. If I recall correctly, it could not be done, easily, on a headless server. I believe it required instantiating a Java applet (canvas) to do the manipulation, hence the need for a windowing system.

I've tried other Java image APIs including ImageMagick, but none could hold a candle to OS X's SIPS when it came to speed. The first time I tried SIPS, in 2005, I resized a 24 megapixel image into a thumbnail. When I hit enter the command prompt immediately returned so I thought it failed. It turns out it worked, flawlessly. A quick call to the command line is an elegant and simple way to implement SIPS in Java, or any other language. If you want to get fancy, you can spin it off in it's own thread so it doesn't block. As always, be careful to avoid any race conditions. (Now that I think about it, it's probably a better idea not to spin it off in it's own thread until you need to scale your code.)

I used SIPS exclusively with my photo sharing website (Epics3) that let users upload photos for storage in their own S3 bucket as a static web page. Although the Epics3 (and Adjix) servers are now defunct, along with Posterous, my images live on in AWS S3:
http://pics.joemoreno.com/2gi3

The downside of SIPS is it hasn't been continuously developed. Some of the things it can't do is overlay text or read GPS EXIF metadata.

But, after reading Dave Winer's request for a text image overlaying API, it got me thinking again. Especially when I proposed this idea for Twitter 519 days ago. I'm surprised there isn't already a popular text image overlaying REST API. Perhaps soon, very soon, there will be the API we seek.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.