krypted.com

Tiny Deathstars of Foulness

Ever need to automate changes to image files? Maybe a LaunchAgent that would watch a specific folder and resize png files that were dropped in there, or a little script that sanitized images as they came in to be a specific size (e.g. Poster Frames)? Well, sips is a little tool built into OS X that can help immensely with this. It will even convert that png to a jpeg or pict to png. Let’s look at using sips. First up, let’s just get the width and height of an image file: sips --getProperty pixelHeight /Shared/tmpimages/1.png sips --getProperty pixelWidth /Shared/tmpimages/1.png Or for dpi: sips --getProperty dpiHeight /Shared/tmpimages/1.png sips --getProperty dpiWidth /Shared/tmpimages/1.png Or to get the format: sips --getProperty format Shared/tmpimages/1.png Now let’s set the property, where the property is format, using the -o option to output a copy of the file to different location: sips --setProperty format jpeg /Shared/tmpimages/1.png -o /Shared/imageoutput/1.jpeg Pretty nifty so far. Now, let’s resize an image using the -z option: sips /Shared/tmpimages/1.png -z 44 70 -o /Shared/imageoutput/converted.png There’s lots more you can do with sips. It also happens to be built into OS X in the /usr/bin folder. Call on it for general still image manipulation. It’s quick and easily scriptable and best of all, a useful tool that can save lots of manual time converting images.

July 24th, 2011

Posted In: Mac OS X

Tags: , , , , , , , , ,

  • Since updating to OS X Lion, I get two silly warnings whenever I invoke sips to reduce the height or width of a png file. Like this:

    MacMini2:~ jk$ sips –resampleWidth 200 /path/to/old/Whatever.png –out /path/to/new/Whatever.png
    /path/to/old/Whatever.png
    [ (kCGColorSpaceDeviceRGB)] ( 0 0 0 1 )
    libpng warning: zero length keyword
    libpng warning: Empty language field in iTXt chunk
    /path/to/new/Whatever.png

    It still seems to work fine, though.