Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'A script to create IMG tags from a folder of pictures' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
A script to create IMG tags from a folder of pictures
Authored by: gshenaut on Dec 23, '04 03:12:09PM
If your text editor lets you insert the output of a shell command into the file, then a small script such as
#!/bin/ksh

i=$*
if [[ "$i" = "" ]] ; then
	read i
fi

w=$(sips -g pixelWidth "$i" | tail -1 | rev | cut -d' ' -f1 | rev)
h=$(sips -g pixelHeight "$i" | tail -1 | rev | cut -d' ' -f1 | rev)

print "<img src=\"$i\" height=$h width=$w>"
may be convenient (I'm sorry for the way too complicated rev|cut|rev stuff, but I can't get my brain to kick in to find something easier).

For example, in vi, you could put in an empty line, then type

!!putimg file.jpg<RETURN>
and the html code will be inserted into your file. (I named the script "putimg".)

The stuff at the top where it reads the name of the image file from standard input is so that if you put the name of the image file by itself on the current line in your text file, then type

!!putimg<RETURN>
the line will be replaced with the html code.

Cheers,

Greg Shenaut

[ Reply to This | # ]