On Wednesday 18 Sep 2002 2:56 pm, Yuen, Alex wrote:
> Hi,
>
> Very newbie.
>
> I was wondering if it is possible to write a CGI (Perl) program to make a
> thumbnail page for my website.
>
> If so, how would I start and use for doing this?
>
> Thanks.
>
> Alex

Hi Alex,

Here's a script based on one I was given a while back.  This is a command-line 
one but should easily be convertable to a CGI.

#!/usr/bin/perl
use strict;

use Image::Magick;

my $im = Image::Magick->new;

umask 0022;

# if passed filenames use them, otherwise do all
my @names = @ARGV ? @ARGV : grep { -f and -B } <*>;

for (@names) {                        # foreach name
  if (/ /) {                          # if name contains a space
    my $old = $_;
    tr, ,_,s;                         # change spaces to _
    $_ .= ".jpg" unless /\.jpg$/;     # append .jpg if missing
    ! -e and rename $old, $_ or next; # skip file if rename fails
    warn "renaming $old to $_\n";
  }
  next if /\.thumb\.jpg$/;            # skip if this is thumbnail
  my $thumb = "$_.thumb.jpg";
  next if -e $thumb;                  # skip if thumbnail exists
  undef @$im;                         # reset (part of) $im
  my $ret;
  $ret = $im->Read($_)                # read file 
    and warn($ret), next;             # or fail and skip
  $ret = $im->Scale(geometry => '100x100')
    and warn($ret), next;
  $ret = $im->Write($thumb)
    and warn($ret), next;
  warn "thumbnail made for $_\n";
}


-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000     


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to