OS X Command line Image Manipulation

“sips — scriptable image processing system”


    DESCRIPTION
    This tool is used to query or modify raster image files and ColorSync ICC profiles. Its functionality can also be used through the "Image Events" AppleScript suite.


‘sips’ lives in /usr/bin/sips and is available on both Tiger and Leopard (OS 10.4, 10.5)

What is it ?  Its a command line tool that lets you quickly resize/resample and convert just about any image format file to a raster based format.  It even works with OS X icon files, .icns, and PDF formats.

In my case, I found this extremely valuable for creating PNG previews from existing PDF documents.

Example 1 – Convert PDF to PNG

sips -s format png mypdf.pdf --out myimage.png

Example 2 – Resize based on width restriction

sips --resampleWidth 64 myimage.png --out myimage-resized.png

Example 3 – Convert and Resize

sips -s format png --resampleWidth 64 mypdf.pdf --out myimage-resized.png

For more information, simply type ‘man sips’ at a terminal command line :)

Converting Multi-Page PDF Documents

I have put together a command-line-only solution for using sips to convert multi-page PDF documents, thanks to the comments by Brian below.

View the solution by proceeding to the following article ‘OS X Image Manipulation – Convert Multi-page PDF with sips and pdftk‘ or by reading the comments.

About these ads

About mcoopet

Co-founder of Code 42 Software, Inc. The guy behind the scenes at work and at home
This entry was posted in Mac, OS-X, Technology and tagged , . Bookmark the permalink.

11 Responses to OS X Command line Image Manipulation

  1. Peter Witham says:

    Great examples, thanks for sharing. I think people overlook the command line for simple things like converting or resizing images.

  2. durranii says:

    I found this really helpful, I do all sorts of this stuff as of late. Thanks for the post.

  3. Brian says:

    Hey I finally discovered SIPS after struggling with some bugs in ImageMagick. SIPS works much easier and I think even faster. Certainly the JPEGs it creates from PDFs look much nicer too.

    However, I have one problem with SIPS and I’m wondering if anyone knows the answer. I have multi-page PDFs I need to convert to multiple images, but SIPS seems to only do the first page…

    Any command arguments to specify all pages? or even a workaround? I really need to do each page, not just the first one..

    Brian

  4. Mitch Coopet says:

    You could do the page extraction with Automator. See this demonstration video here -

    http://www.mac-help.com/images/Automator001.mov

    Its fairly trivial to change it to a script that accepts a dropped PDF file and performs the page extraction task. You could then set up a watch folder script that runs SIP on the extacted PDF files.

  5. Mitch Coopet says:

    Brian -

    For a pure command line solution, I think you may be able to use pdftk in conjunction with SIPS. You’ll have to install pdftk which is an open source command line utility for manipulating PDF documents.

    Checkout the site

    http://www.accesspdf.com/pdftk/index.html

    If you’re running Mac ports, you can install it via command line

    sudo port install pdftk

    Once installed, simply issue the command

    pdftk multi-page.pdf burst

    where multi-page.pdf contains the pages you want extracted. This will result in each page being written as its own PDF document in your current working directory. The filenames will be ‘pg_000x.pdf’ where x is the page number.

    Integrating with sips at this point is trivial, as you can customize the output filenaming scheme of pdftk to whatever you need.

  6. Brian says:

    Hey that’s helpful. I’m doing all my processes through a launchd process that watches a folder, so I prefer command line over automator (though it’s not entirely out of the question, but I’d prefer to avoid making spaghetti out of it all with so many different methods)

    I ended up going with Ghostscript for the time being. It has a half decent PDF > JPEG method that accounts for multiple pages. I can’t say I’m crazy about the output quality (it’s fairly aliased), and would prefer some color fidelity with ICC conversion profiles (I’m converting CMYK PDFs to RGB JPEGS).

    I will definitely take a look at pdftk (installing it now as I type) and see how it works. If it works easily in conjunction with SIPS, I know the resulting images will be nice and clean.

    Thanks again guys!!

  7. bob says:

    lose the wordpress snapshots; makes the site painfully slow and annoying.

  8. sean says:

    Very useful, I had no idea there was such a tool already in my OS.

  9. jorge says:

    Thanks for this useful post. I wonder: is there any option to put a white background on the png?

  10. Shark Sandwich says:

    What about if you want to resize by percentage? I have a folder full of images of different sizes, and I know I want to resize them all to 63% of their original size. Can sips do that? If not, what can? I know Automator can, but I really want a command-line solution.

  11. Olga says:

    This is perfect! Thank you!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s