You don't really need to check whether the image is 800x600 or 600x800, actually. Image::Magick will do that on its own if you convert to '108x108', converting the longest side to 108 px, and the shortest to whatever it would proportionally amount to.

Here is some code I've been using to generate an HTML index for images files, with thumbnails :
#!/usr/bin/perl use strict; use warnings; use utf8; use Image::Magick; my $dir = $ENV{'PWD'}; chomp(my @files = `ls $dir`); if (-e "$dir/thumbs") { print STDERR "The directory $dir/thumbs already exists. Files inside + may be replaced.\n Do you want to continue ? (y/n)"; chomp(my $choice = <STDIN>); if ($choice =~ /^n/) { print STDERR "Aborted by user.\n"; exit(1); } else { if (!($choice =~ /^y/)) { print "Please enter 'y' or 'n' :"; } } } mkdir "$dir/thumbs" || die "Unable to create directory $dir/thumbs :$! +"; if (!(-e "$dir/index.html")) { open (OUT, ">:utf8", "index.html") || die "Unable to open file $dir/ +index.html : $!" } print OUT <<HERE; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w +3.org/TR/xhtml1/xhtml1-strict.dtd"> <html encoding="utf8"> <head> </head> <body> <h1>Contents of directory $dir</h1> HERE foreach my $file (@files) { if ($file =~ /\.(jpg|jpeg|bmp|gif|png)/) { my $image = Image::Magick->new(); $image->Read($file); $image->Resize('150x150'); $image->Write("thumbs/t_$file"); print OUT "<a href=\"$file\"><img src=\"thumbs/t_$file\"></a>\n"; } } print OUT "\n</body>\n</html>\n"; close OUT;
Lu.

In reply to Re: thumbnails generator by Lu.
in thread thumbnails generator by spx2

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.