foxfirefey: A guy looking ridiculous by doing a fashionable posing with a mouse, slinging the cord over his shoulders. (geek)
[personal profile] foxfirefey posting in [community profile] python
Don't know if this could be useful to anyone else, but I just wrote a wee script that generates the HTML for images in a directory on my web server, to make it easier to post about them to my journal:

import Image, sys

if len(sys.argv) < 3:
    print "Usage: %s [baseurl] [filename] [filename] ..." % sys.argv[0]

# put this in front of each image file name
baseurl = sys.argv[1]

# cycle through all image names given on the command line
for imagefile in sys.argv[2:]:

    try:
        i = Image.open(imagefile)
        ( width, height ) = i.size
        print '<img src="%s/%s" width="%d" height="%d" alt="" />' \
          % ( baseurl, imagefile, width, height )
    except IOError:
        print "Could not process %s" % imagefile


Example of running it:

python imagehtml.py http://mywebsite.com/images *.png
<img src="http://mywebsite.com/images/articfox-fluffy-20110123.png" width="400" height="356" alt="" />
<img src="http://mywebsite.com/images/gorilla-matron-20110123.png" width="500" height="373" alt="" />
<img src="http://mywebsite.com/images/kookaburra-20110123.png" width="400" height="602" alt="" />
<img src="http://mywebsite.com/images/prettybird-20110123.png" width="400" height="602" alt="" />
<img src="http://mywebsite.com/images/snowleopard-crouch-20110123.png" width="700" height="495" alt="" />
<img src="http://mywebsite.com/images/snowleopard-stalk-20110123.png" width="800" height="533" alt="" />
<img src="http://mywebsite.com/images/snowleopard-tailfence-20110123.png" width="700" height="465" alt="" />
<img src="http://mywebsite.com/images/snowyowl-20110123.png" width="400" height="457" alt="" />
<img src="http://mywebsite.com/images/toucan-pair-20110123.png" width="500" height="338" alt="" />
<img src="http://mywebsite.com/images/wallaby-toes-20110123.png" width="500" height="332" alt="" />
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

February 2024

S M T W T F S
    123
45678910
11121314 151617
18192021222324
2526272829  

Style Credit

Expand Cut Tags

No cut tags