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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |