An Image Dimensions Droplet

Question: what's a "droplet"?

Answer: a drag-and-drop applet, i.e., a small program on the desktop that runs when a file is dropped onto its icon.

Extracting an Image's Dimensions for Use in HTML

A browser-friendly Web site should provide width and height attributes for each <img> element. Unfortunately, getting an image's width and height dimensions is an overly complex task. For even a 1K GIF image, I have to open a file in Photoshop, use a menu command to display the dimensions, then try to keep the width and height in mind as I switch back to my HTML editor. It's bad enough to do this for one file, and worse for multiple files.

How about this for an alternative? You have a special icon on your desktop. When you want an image's dimensions in HTML-ready format, you drag the file to the icon and drop it. This starts up a little program that reads the image file, extracts its dimensions, formats them for use in HTML, puts them on the clipboard, then exits silently. No Photoshop, no menu commands. Just drag, drop, application switch, paste.

That's what this image dimensions droplet is. Drop an image file onto it, and a moment later its dimensions will be on the clipboard, ready for pasting into an <img> element:

width="243" height="455"


  1. Download the droplet. It's a Perl script, so you'll need to install Perl if you don't have it.

  2. Create a one-line batch file that invokes the droplet, like so:
    perl %1

  3. Create an icon on your desktop that invokes the batch file. (Here's an icon, if you need one.) I set the batch file to run in a minimized window that closes when the program exits.

Test it by dragging a GIF, JPEG, or PNG file onto the icon, opening a text editor, and pasting the contents of the clipboard.

I wish I had this years ago.

Linux, BSD, and Mac OS X too!

Adrian Tymes adapted this to run from the Linux command line, writing results to standard out:

>perl myPic.gif
width="235" height="126"

Scott Crevier improved the OS detection logic and tested it on several additional platforms, including BSD.

Barak Shilo whipped up a way to use drag-and-drop on a Mac running OS X:

  1. Save in your home directory.

  2. Open the Script Editor and create a new script:

    on open file_
            set file_ to quoted form of POSIX path of file_
            set the clipbaord to (do shell script "perl ~/ " & file_)
    end open
  3. Save as an Application.

Thanks to Adrian, Scott, and Barak.


Last updated 30 October 2006
All contents ©2002 Mark L. Irons.