I never used GD before today, so I made a little program to compare the output given by GD and Image::Magick. Here is the code:

#!/usr/bin/perl use strict; use warnings; use GD; use Image::Magick; use vars qw( $default_orientation $default_width $default_height $file +name ); $default_orientation = 'vertical'; $default_width = 150; $default_height = 100; $filename = 'image.jpg'; thumb_with_imagemagick($filename, 'im.jpg'); thumb_with_gd($filename, 'gd.jpg'); exit; sub thumb_with_imagemagick { my ($infile, $outfile, $image, $error, $x, $y, $size, $format, $width, $height); ($infile, $outfile) = @_; $image = Image::Magick->new; $error = $image->Read($infile); if (!$error) { ($x, $y, $size, $format) = $image->Ping("$infile"); ($width, $height) = thumbnail_dimensions($x, $y); $image->Scale(width=>$width, height=>$height); $error = $image->Write($outfile); } return $error; } sub thumb_with_gd { my ($infile, $outfile, $image, $error, $x, $y, $width, $height, $thumb); ($infile, $outfile) = @_; $image = GD::Image->new($infile); ($x, $y) = $image->getBounds(); ($width, $height) = thumbnail_dimensions($x, $y); $thumb = new GD::Image($width, $height); $thumb->copyResized($image, 0,0 , 0,0 , $width,$height , $x,$y +); open(IMAGE, '>', $outfile); print IMAGE $thumb->jpeg; close(IMAGE); } sub thumbnail_dimensions { my ($x, $y, $ratio, $height, $width); ($x, $y) = @_; $ratio = $x / $y; if ($default_orientation eq 'height') { $height = $default_height; $width = int($height * $ratio); } else { $width = $default_width; $height = int($width / $ratio); } return $width, $height; }

I made some tests over few images and I still prefer the thumbnails produced by ImageMagick.

Ciao, Valerio


In reply to Re: Creating thumbnails by valdez
in thread Creating thumbnails by cal

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.