The interesting part of this script is the various methods for closing the popup window. You can use which one suits your purpose. I included 3 methods. The onBlur closes the popup when the mouse leaves it. This can be handy if all the images have different dimensions, otherwise the popup will stay open and display a mis-matched photo to popup. Play with it, and you will see. If all your images are the same size, it works great, because you can remove the onBlur and let each new thumbnail be displayed in the same window.
#!/usr/bin/perl use warnings; use strict; use Image::Magick; #watch the width of your picture names #they can widen the table cells if too long umask 0022; my $image = Image::Magick->new; my $count = 0; open(OUT,">thumbs.html"); print OUT<<End_Header; <html> <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"> <!-- function popitup(url,w,h) { newwindow=window.open(url,'name',"width="+w+",height="+h+""); newwindow.document.open(); newwindow.document.write('</body></html>'); newwindow.document.write('<html><title>'+url+' CLICK TO CLOSE</title>< +body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" o +nBlur="self.close()" onClick="self.close()">'); newwindow.document.write('<img src='+url+' height='+h+' width='+w+' a +lt=['+url+'] align=center >'); newwindow.document.write('<INPUT type="button" value="Close Window" on +CLick="window.close();">'); newwindow.document.write('</body></html>'); newwindow.document.close(); if (window.focus) {newwindow.focus()} return false; } // --> </SCRIPT> <body> <table align=left bgcolor=9999CC border=2 cellpadding=2 cellspacing=2> <tr> End_Header my @pics= <*.jpg>; foreach my $pic (@pics){ $count++; my ($picbasename) = $pic =~ /^(.*).jpg$/; my $ok; $ok = $image->Read($pic) and warn ($ok); my ($w,$h)= $image->Get('columns','height'); my $thumb = $picbasename . '-t.jpg'; $ok = $image->Scale(geometry => '100x100')and warn ($ok); $ok = $image->Write($thumb)and warn ($ok); my ($tw,$th)= $image->Get('columns','height'); my $picoptions= $w.'x'.$h.'x'.$tw.'x'.$th; print "$pic\t$picoptions\n"; undef @$image; print OUT<<EOTR; <td align=center><a href="javascript:;" onClick="return popitup('$pic' +,'$w','$h')"><img alt= [$pic-thumbnail] src=$thumb height=$th width=$ +tw></a><br>$pic</td> EOTR if($count == 4){print OUT "</tr><tr>"; $count = 0}; } print OUT<<EOHTML; </tr> </table> </body> </html> EOHTML close OUT;
|
|---|