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: La casa de mi Dios
Visited: 458
Uploaded at: 2003-04-04 21:02:32
En la Casa de Dios, mejor es estar un día en sus atrios que mil fuera de ellos.
Title: Estoy Maravillado
Visited: 316
Uploaded at: 2003-04-04 20:50:49
Arboles de otoño, Maravillas del Señor
Title: Cristo Mi Piloto sé
Visited: 2017
Uploaded at: 2003-04-04 21:36:13
Navegando hacia el inmenso mar, Cristo sea Nuestro Piloto
Title: Permanece en Cristo
Visited: 278
Uploaded at: 2003-04-04 21:11:26
Uvas. Jesús dijo: Yo soy la vid, separados de mi nada podeis hacer.
Title: Descenderá sobre ti
Visited: 843
Uploaded at: 2003-04-04 22:08:22
La Paloma, simbolo del Espíritu Santo.
Title: Olas Inmensas
Visited: 768
Uploaded at: 2003-04-04 21:32:20
Olas del mar embravecido, la Voz de Dios puede Calmarlas
Title: En los cielos
Visited: 201
Uploaded at: 2003-04-04 20:59:24
Atardecer en el mar, nos recuerda a quién tenemos en el cielo, al Dios Todopoderoso
Title: Maravilloso Dios
Visited: 522
Uploaded at: 2003-04-04 21:26:43
Hermoso atardecer en el mar, maravilla del Maravilloso Dios.
Title: Llena de Su Gloria
Visited: 255
Uploaded at: 2003-04-04 20:55:56
Flores en primavera, llenan la Tierra de la Gloria del Señor.
Title: Como la palmera
Visited: 342
Uploaded at: 2003-04-04 22:19:45
El justo florecerá como la palmera
Title: Jesucristo mi refugio
Visited: 661
Uploaded at: 2003-04-04 21:39:19
Las aves contemplando el mar desde una roca, Jesucristo es mi roca, mi refugio.
Title: Después de la tormenta
Visited: 268
Uploaded at: 2003-04-04 21:08:47
Recuerda que Jesucristo puede calmar cualquier tempestad.