FAGZAL's blog

Channels : ALL    Perl 5  (2)   PET  (2)   Misc.  (1)   Perl-2-PHP  (1)  
http://fagzal.syntaxpoint.com/blog/t208

A very typical web programming task is to take a directory which contains a bunch of images, and create a thumbnail gallery out of it. The Album module does this very professionally, and an actual industry - TGP sites - is built around this idea.

In theory, it is relatively easy to create an album. All you have to do is to list the directory, get the images, resize them and then display the thumbnails on a (HTML) page with links to the original images. So let's make this easey in practice, too!

Using a few PET built-ins, I am going to show you how to create an album without writing any Perl code - using only 6 lines of code. We will have a page list.pet which lists the thumbnails, and another one called show.pet, which shows the big (original) image.

list.pet
<io:getDir=images dir="html/images" exti="jpg|jpeg" />
[% FOREACH image = images %]
 <a href="/show.pet?file=images/${image.file}"><image:thumbnail 
   maxwidth=
"100" maxheight="100"  file=image.path border="0" /></a>
[% END %]


show.pet
<img src="/${Query.file}" />


That's it! Of course this has no extra HTML, so if you want to make it look nice, you have to put in some CSS & DIVs & TABLEs and whatnot, but this is all the codig you need.

Now let's go into the details!

More »

Direct URL of this entry : http://fagzal.syntaxpoint.com/blog/b177
Number of comments:0


See GALLERY»

PET
entries
1. PET tricks
   2007, November 17., 0h
2. Creating a TGP-like gallery using PET in 6 lines
   2007, November 17., 0h

Archive
rss newsfeed icon
Advertisement

Title: Bent Over
Visited: 0
Uploaded at: