in reply to RE: Re: GD Module
in thread GD Module

Image::Magick is a Perl interface into libmagick. You can get it from CPAN (or click the link to the left). It will work with any image format that libmagick supports (GIFs are a little funny these days. I don't remember if they'll work or not).

The code example will (should) work if you change the '\' to '\\', since you need to escape slashes. Or, you could use single quotes instead. Doing something with the returned values is up to you. If you're going to discard them, you could just leave the variable off.

--Chris

Updated: I was thinking that ImageMagick used GD, but it doesn't. It's a standalone library for image manipulation. GD is for doing plots and graphs. Sorry about that.

Replies are listed 'Best First'.
RE: RE: RE: Re: GD Module
by dvst8 (Initiate) on Jun 20, 2000 at 19:24 UTC
    thank you much appreciated! /d8
    hmmmm
    by dvst8 (Initiate) on Jun 20, 2000 at 23:03 UTC
      Forgive me for being a dumb Perl newbie...
      I've gone through your code, and it all makes sense except for the confess stuff... what does that mean?

      I'm using PerlScript in an ASP page, and tried out your sub... here is what my page looks like:
      <%@ LANGUAGE = PerlScript my $globalPreviewMaxDimension = 100; sub util_photo_GenerateThumbnail { my ($source, $destination) = @_; my $preview = Image::Magick->new; my $x = $preview->Read ($source); confess "$x" if "$x"; my ($xSize, $ySize) = $preview->Get ('width', 'height'); # Get the p +ictures dimensions # # Calculate dimensions of thumbnail # my $scaleFactor; my $previewX; my $previewY; # # Only scale if either axis is larger than the preview size # if ($xSize > $globalPreviewMaxDimension || $ySize > $globalPreviewMa +xDimension) { if ($xSize > $ySize) { $scaleFactor = $globalPreviewMaxDimension / $xSize; $previewX = $globalPreviewMaxDimension; $previewY = int ($ySize * $scaleFactor); } else { $scaleFactor = $globalPreviewMaxDimension / $ySize; $previewY = $globalPreviewMaxDimension; $previewX = int ($xSize * $scaleFactor); } $x = $preview->Scale (width=>$previewX, height=>$previewY); confe +ss "$x" if "$x"; $xSize = $previewX; $ySize = $previewY; }
    hmmmm
    by dvst8 (Initiate) on Jun 20, 2000 at 23:04 UTC
      Forgive me for being a dumb Perl newbie...
      I've gone through your code, and it all makes sense except for the confess stuff... what does that mean?

      I'm using PerlScript in an ASP page, and tried out your sub... here is what my page looks like:
      <code> <%@ LANGUAGE = PerlScript my $globalPreviewMaxDimension = 100; sub util_photo_GenerateThumbnail { my ($source, $destination) = @_; my $preview = Image::Magick->new; my $x = $preview->Read ($source); confess "$x" if "$x"; my ($xSize, $ySize) = $preview->Get ('width', 'height'); # Get the pictures dimensions # # Calculate dimensions of thumbnail # my $scaleFactor; my $previewX; my $previewY; # # Only scale if either axis is larger than the preview size # if ($xSize > $globalPreviewMaxDimension || $ySize > $globalPreviewMaxDimension) { if ($xSize > $ySize) { $scaleFactor = $globalPreviewMaxDimension / $xSize; $previewX = $globalPreviewMaxDimension; $previewY = int ($ySize * $scaleFactor); } else { $scaleFactor = $globalPreviewMaxDimension / $ySize; $previewY = $globalPreviewMaxDimension; $previewX = int ($xSize * $scaleFactor); } $x = $preview->Scale (width=>$previewX, height=>$previewY); confess "$x" if "$x"; $xSize = $previewX; $ySize = $previewY; } %
    hmmmm
    by dvst8 (Initiate) on Jun 20, 2000 at 23:08 UTC
      Forgive me for being a dumb Perl newbie...
      I've gone through your code, and it all makes sense except for the confess stuff... what does that mean?

      I'm using PerlScript in an ASP page, and tried out your sub... here is what my page looks like:
      <code> <%@ LANGUAGE = PerlScript my $globalPreviewMaxDimension = 100; sub util_photo_GenerateThumbnail { my ($source, $destination) = @_; my $preview = Image::Magick->new; my $x = $preview->Read ($source); confess "$x" if "$x"; my ($xSize, $ySize) = $preview->Get ('width', 'height'); # Get the pictures dimensions # # Calculate dimensions of thumbnail # my $scaleFactor; my $previewX; my $previewY; # # Only scale if either axis is larger than the preview size # if ($xSize > $globalPreviewMaxDimension || $ySize > $globalPreviewMaxDimension) { if ($xSize > $ySize) { $scaleFactor = $globalPreviewMaxDimension / $xSize; $previewX = $globalPreviewMaxDimension; $previewY = int ($ySize * $scaleFactor); } else { $scaleFactor = $globalPreviewMaxDimension / $ySize; $previewY = $globalPreviewMaxDimension; $previewX = int ($xSize * $scaleFactor); } $x = $preview->Scale (width=>$previewX, height=>$previewY); confess "$x" if "$x"; $xSize = $previewX; $ySize = $previewY; } %