New utility: image

2006-11-17 13:49:12 -08:00

When I was writing “The fun of length-declared strings”, I needed to resize that lightbulb photo down to something more suitable for a blog post. Normally, I’d just use Photoshop, but I’m not on a PowerPC Mac anymore, so Photoshop 5.5 won’t run. So I needed to use other things.

The crop was easy; Preview can do that. But I also needed to scale it, and Preview can’t do that. I tried installing the (sigh) Photoshop CS2 tryout, but that didn’t work; the installer fails while it’s doing something ambiguous to Photoshop’s help files. No surprises there.

And I didn’t want to use iPhoto for it. That would mean importing it into my Library, and I only want to do that for my photos.

The alternatives are sips and GIMPShop. I passed on sips because I don’t know how sips scales images (i.e. which interpolation quality it uses), and because it makes you specify the dimensions backward for no obvious reason. GIMPShop is out of the question because (1) it is slow, and (2) it is an X11 application, and I do not like running X11 applications on my shiny Aqua desktop.

This left only one solution: Write my own. So that’s exactly what I did.

Introducing image. image is a utility that can both scale and convert images; this includes rasterization of vector art. Here are the examples from the webpage:

  • % image piechart.eps pdf
    Output: piechart.pdf
  • % image lightbulb.jpg 50%
    Output: lightbulb-50%.jpg
  • % image lightbulb.jpg 240
    Output: lightbulb-240.jpg (scaled proportionally)
  • % image lightbulb.jpg 320x240
    Output: lightbulb-320×240.jpg
  • % image lightbulb-orig.tiff 50% jpg lightbulb.jpg
    Output: lightbulb.jpg

Pretty useful, huh? I hope so.

Enjoy.

5 Responses to “New utility: image”

  1. Hub Says:

    Have you tried seashore?

    http://seashore.sf.net/

  2. Simone Manganelli Says:

    Meh on Seashore. It’s a nice application, but for scaling images, it’s just tedious. Actually, I often use it for doing precise cropping according to pixel values and then scaling images, and I have to — grr — click that annoying “Also apply to full size layers” checkbox every single time when I adjust the boundaries. It seems to try to emulate the interface of Adobe Photoshop, which is horrible for occasional use.

    I imagine this command-line utility will be useful next time I do need to do image scaling. Can you supply a folder as an argument for quick batch processing? That would be sweet.

  3. rtmfd Says:

    Have you tried ImageMagick? I believe it has a DarwinPort and a fink installer. If that’s not to your liking, I’ve got a Universal Binary build of ImageMagick I could pass along to you. I’ll be on IRC if you’re interested.

  4. Peter Hosey Says:

    Hub: I’d forgotten about Seashore. I’d rejected it before because it’s not Photoshop, but for simple scaling and conversion, it’s not bad.

    It would be nice if it had a crop tool like Preview’s, though. Or even simply a fixed-size rectangular marquee like Photoshop offers.

    Simone: Not in the current version, but it’s an interesting idea. I fear what it would do to the already-ugly code.

    In the meantime, you can use find topdir -foo blah -bar blah -exec image '{}' 50% jpg ';'. Change up the arguments to find and image as required.

    rtmfd: ImageMagick is horribly bloated and underdocumented. My main problem with it was always figuring out which algorithm to use; it offers about a dozen, IIRC, and they are all presented by name with no indication of which ones are better for speed than quality vs better for quality than speed. I’d rather have a range of “fast”, “mediocre”, and “best”, or in this case, just “best”.

    Even so, maybe I can find something else to do with it.

  5. Brian Ganninger Says:

    I ran into the same conundrum a few months ago but I cheated and took an even simpler solution – I threw together an Automator workflow to take a folder of images, ask me the resize percent or new values, and then go to town.

Leave a Reply

Do not delete the second sentence.