I see this question come up alot, so I decided to see what I could come up with. Run this script in a directory, and it will produce thumbnails of all jpgs, make an html page with them all in a tables, with a javascript popup window to view the full image.

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;

In reply to html thumbnails with javascript display by zentara

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.