Quick Image Dimension Finder

If you’re a markup writer you’ll spend an annoying amount of your time getting the width and height of images for the <img> tag’s width and height attributes. I’m always going back and forth between my editor and Photoshop to get the width and height values.
This is an OS X service that lets you right click on an any kind of image and get the dimensions as attributes copied to the clipboard. In other words, doing this to a 200 by 150px image will give you width=”200” height=”150”. Then you can paste that in your markup in one fell swoop.
It’s such a small thing but it’s always ground my gears, I’m glad to have it done.
I’ve only tested on Snow Leopard.
Here’s how to install it:
1. Copy it to your ~/Library/Services directory. Make that Services directory if you don’t have it.
2. It’ll now be up in the Finder > Services menu as Get Image Dimensions, when you select an image. Just click on the image’s icon to select it. After you do this once to an image it’ll move itself into the right click menu, for any image.
If it doesn’t show up in your Services menu you might need to relaunch Finder, or log out and back in.
Dev Notes*
The hardest part of building this was navigating the obtuse OS X Services infrastructure. Michael Schade’s blog post (http://mschade.me/creating-a-mac-os-x-service-part-i) was extremely helpful. Working out the correct plist settings for this specific task was largely a matter of trial and error.
The code is included. It’s public domain, etc.

3 comments

Aha, almost what I was looking for!

Is it possible to just show the image dimensions (width x height) in the contextual menu without installing the service, I don't need to copy/paste?

Many thanks!
Doug, this is awesome! Can you bind it to some quick key combination so you don't have to use the flyout menus like a plebe?
ebr4him, I don't think that it's possible to update the text of the contextual menu through the services API. If you've got an example of that happening please send it my way, I could definitely be wrong.

Sabih, I read that it's sort of bad practice to pre-assign keyboard shortcuts to these things, because it might stomp on existing short cuts. You can assign your own shortcut though. See here: http://www.macworld.com/article/139829/2009/04/shortcutservices.html