A script to create IMG tags from a folder of pictures

Dec 22, '04 09:03:00AM

Contributed by: Anonymous

If, like me, you do most of your HTML coding in a text editor, then perhaps you've found one of the most tiresome chores is loading every little image you've made for a button or background into Preview or similar package to find out its dimensions for correct handling in HTML (i.e. <img src=filename height=y width=x>).

To alleviate this a little, I've written a small Python script. When run from the Terminal, the script will search for all JPEG, GIF or PNG images in the current directory, and output a user-named HTML file. The file will include each image's name plus its dimensions in HTML format, ready for you to copy and paste into your working document. I've found it's saved me a lot of time on the site I'm currently building, and I hope it might help you, too.

My imgDetails.py script [view source] uses the extremely-useful Mac OS 10.3 command line utility sips, which allows you to query (and modify if you wish) images from the Terminal. This utility was only added in 10.3, hence my script will not work on prior versions of Mac OS X.

[robg adds: I tested this one, and it worked as described -- you get a nice HTML file that contains the IMG tags with the proper 'width' and 'height' tags already included.]

Comments (13)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20041220171133228