I've seen allot of people asking for thumbnail generators and
scripts solving some problem similar to this.
I also needed to do this recently so I spent some minutes writing a script
for it.
It's not the most interesting/efficient thing but it cuts some time and
probably it will help somebody.
I tested it using Windows.It is dependant on Image Magick.
The exact behaviour is the following:
1)get all files in directory
2)traverse each and every one of them and see if it has usual image extension
3)if 2 happens then it gets dimensions of image
4)if height>width then it uses some predefined resolutions to which it creates new
copies of the image scaled down to the predefined resolutions.
5)if width>height it reverses the predefined resolutions height with width and does the same
as described in step 4


use strict; use warnings; my @Ll=(800,600); my @Ls=(108,81); sub get_dimensions { my ($N)=@_; my $o = `identify $N`; my ($X,$Y) = $o=~ /\ (\d+)x(\d+)\ /; return ($X,$Y); } sub convert { my ($X,$Y,$N,$M)=@_; #X,Y dimensions to convert to #N-original name of file #M-name of converted/modified file my $cmd = "convert -resize %s %s %s"; $cmd=sprintf $cmd,"$X".'x'."$Y!",$N,$M; `$cmd`; #print $cmd; } sub convert_small_large { my ($N)=@_; my ($name,$ext)=split '\.',$N; my ($Xi,$Yi)=get_dimensions $N; if($Xi>$Yi) { convert @Ll,$N,"$name-l.$ext"; convert @Ls,$N,"$name-s.$ext"; } else { convert reverse @Ll,$N,"$name-l.$ext"; convert reverse @Ls,$N,"$name-s.$ext"; }; } my @files = <*>; print join "\n",@files; for (@files) { print "converting $_ ...\n"; my $namelow=lc $_; next unless $namelow =~ /(gif|bmp|jpg|wmf|jpeg|png)$/; eval { convert_small_large $_; }; }

In reply to 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.