Try the GD module. Here is some code I have for creating thumbnails
(untested as it's stripped down from a bigger script). Thumbnails have a _
prepended to them. They're not great thumbs, there is no anti aliasing done
on them. For better image handling you'll need to look at the ImageMajick
(sp??) module but that's overkill for my needs.

use GD;

# Set new height of thumbnail
my $new_y = 120;

# Set path to files
my $directory = "c:/image/folder";

# Collect file names here
my @files = qw(one.jpg two.jpg);

foreach $file(@files) {
    &thumbnail($file);
}

sub thumbnail {
        my $file = shift;

        return if -e "$directory/_$file";

      print "Generating thumbnail for $file\n";

        # Load source image
        my $srcImage = newFromJpeg GD::Image("$directory/$file");

        # Get image size
        my ($orig_x,$orig_y) = $srcImage->getBounds();

        # Calculate new image width based on fixed size of $new_y
        my $new_x = ($new_y / $orig_y) * $orig_x;

        # Create new object for thumbnail
        my $thumb = new GD::Image($new_x,$new_y);

      # Copy the source image to the thumbnail image, resizing in the
process
        
$thumb->copyResized($srcImage,0,0,0,0,$new_x,$new_y,$orig_x,$orig_y);
              
        # Save your thumbnail
        open(OUT,">$directory/_$file") || die "Could not create
$directory/$file as thumbnail $directory/_$file: $!";
        binmode OUT;
        print OUT $thumb->jpeg();
        close(OUT);
        
}

HTH

John

-----Original Message-----
From: Gary Stainburn [mailto:[EMAIL PROTECTED]] 
Sent: 26 March 2002 10:00
To: [EMAIL PROTECTED]
Subject: Batch creation of thumbnails


Hi all,

I need to be able to create thumbnails for a group of .jpg files overnight, 
and I was wondering if there were any perl modules that anyone could suggest

for this one?

I'm going to take a stroll over to CPAN, but I believe personal experiences 
always help.

-- 
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]


--------------------------Confidentiality--------------------------.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.



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

Reply via email to