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.
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"
Download the droplet. It's a Perl script, so you'll need to install Perl if you don't have it.
Create a one-line batch file that invokes the droplet, like so:
perl imgdim.pl %1
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.
Adrian Tymes adapted this to run from the Linux command line, writing results to standard out:
>perl imgdim.pl 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:
Save imgdim.pl
in your home directory.
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 ~/imgdim.pl " & file_) end open
Save as an Application.
Thanks to Adrian, Scott, and Barak.
This has been tested on:
If the image isn't a GIF or PNG, the applet assumes it's a JPEG. This eliminates the DOS 8+3 filename mangling problem, but adds a side effect: if the file isn't one of the recognized types, it returns (-1,-1) for the image's dimensions.
If you give the script a filename that doesn't exist, it exits silently. (If you'd prefer an error message, uncomment a line in the code.)
The batch file is necessary under Windows 95/2000. You can't invoke the droplet directly from the icon. If you try, the filename is passed as another parameter to the Perl interpreter, and will be ignored. There might be a way around this on Windows NT 4.0/2000; see the ActiveState Perl F.A.Q.
On Windows XP, you can invoke perl imgdim.pl %1
directly as a shortcut.
If you don't like dragging and dropping, you can set this up to run from the context menu in Windows Explorer. However, you have to add keys to the registry manually. Here's how to add this to the context menu for GIF files:
Open the registry editor.
Expand the HKEY_CLASSES_ROOT
key and look for the key corresponding to GIF files. On my system, the .gif
key pointed to another key, giffile
. That's the key we want; open it.
There should be a subkey named shell
. Add it if it isn't there.
Under shell
, add a new subkey named Dimensions
(or whatever you want the command to appear as on the context menu).
Create a new binary value in this key called EditFlags
. Give it a value of 01 00 00 00
Create a subkey called command
.
In the command
subkey, modify Default
. Add the full path to your DOS batch file, e.g., C:\apps\image.dimensions\imgdim.bat %1
That should do it. You'll have to repeat this process for JPEG and PNG file types as well.
Last updated 30 October 2006
http://www.rdrop.com/~half/General/Downloads/image.dimensions.droplet.html
All contents ©2002 Mark L. Irons.