Simple Zope Photo Album

Karsten W. Rohrbach karsten at rohrbach.de
Sat Jan 4 10:48:28 CET 2003


mlorfeld <tutal at msn.com> wrote:
[...]
> image, python script, wiki).  So basically I'm looking for a Q&D
> pytyhon/dtml/html code snippit that will dynamically create a photo
> album.  Any suggestions?

- Install ImageMagick locally
- Create a work directory hierarchy
    $ mkdir work
    $ mkdir work/img
    $ mkdir work/thumb
- Put all images into ./work
- run ImageMagick over them to create jpg and thumbnails
  (presented script is from my work dir wich contains only PNG images,
  I publish JPEG pictures)
    #!/bin/sh
    for i in *.png
    do
	FNAME=`echo -n ${i} | sed s/.png$//`
	echo ${FNAME}
	convert ${i} ./img/${FNAME}.jpeg
	convert ${i} -geometry 96x96 ./thumb/${FNAME}.jpeg
    done
- Now FTP to your Zope server and upload the two directories relative to
  you gallery container object (Folder) - I use NcFTP for that
  (recursive put)
- on the Zope side you can install a simple DTML method which creates a 5
  by somewhat table of thumbnails. [1]
    <dtml-let numpics="_.len(img.objectIds(['Image']))">
    <table class="gallery" align="center">
    <dtml-in expr="img.objectValues(['Image'])" sort="id">
	<dtml-let seq=sequence-number>
	<dtml-if "(seq - 1) % 5 == 0">
	    <tr>
	</dtml-if>
	<td class="gallery"><a href="pics/<dtml-var "getId()">" 
	    target="_blank"><img src="thumbs/<dtml-var "getId()">" 
            border="0" alt="[]"></a></td>
	<dtml-if "seq % 5 == 0">
	    </tr>
	</dtml-if>
	</dtml-let>
    </dtml-in>
    </tr>
    </table>
    <p align="right">
    (<dtml-var numpics > Photos)
    </p>
    </dtml-let>

The beneift is, that you won't need any additional Zope products. The
drawback is the hackish generation of URLs (which produces relative URLs
that might lead to acqusition problems, depending on where you put the
DTML method).

Regards,
/k

[1] http://www.rohrbach.de/Content/Karsten/Pics





More information about the Python-list mailing list