Reputation: 35
I am trying to resize the image using GD image library and perl, but when it is resized the quality of image is not same as original uploaded image.. Do you guys have any suggestion?
Below is my code
my $dest_w = $width;
my $dest_h = $width * ($h / $w);
my $dest = GD::Image->new($dest_w, $dest_h, 1);
$dest->copyResampled($src, 0, 0, 0, 0, $dest_w, $dest_h, $w, $h);
open OUT, ">$target" or die "Could not save to $target";
binmode OUT;
print OUT $img->jpeg($quality);
close OUT;
Anything wrong with my code? thanks for advice
Note: I uploaded .png image. Even if uploaded .jpeg image, the quality of the image is also dropped
Upvotes: 1
Views: 1962
Reputation: 51
Do you have to use GD? If you use GD to resize an input image eg a .jpg in Perl even with
my $quality = 100;
print OUT $resultimage->jpeg($quality);
then at least in its present versions, as I have tested them just now, both GD and Imlib2 (also there quality set to 100) produced somewhat more blur than such as ImageMagick in Perl. In addition, best results come if resized jpg image is saved to .gif (or .png), eg:
#! /usr/bin/perl
use Image::Magick;
my($inimage, $resultimage, $info);
$inimage = Image::Magick->new;
$info = $inimage->Read('exampleimagebig.jpg');
warn "$info" if "$info";
$info = $inimage->Resize(geometry=>'500x500', blur=>0.9);
warn "$info" if "$info";
# In the next line you can write .png or if you must, .jpg:
$info = $inimage->Write('exampleimage500.gif');
warn "$info" if "$info";
Upvotes: 1
Reputation: 182
Try define $quality as in my example and try it with png on input.
binmode OUT;
$quality=100;
print OUT $img->jpeg($quality);
Upvotes: 0