convert resize VS perlMagick resize
Posted: 2007-02-22T04:20:05-07:00
I'm busy setting up a web site.
I'd like to allow upuloading pictures. But to save the disk space I want to resize the pictures
to have only picture 640x480.
Please find here included a test script about resizing.
My problem is : I can use convert from withing that script and it gives a clear sharp image.
but all the different possibilities of perlMagick Resize are just giving a blurred image.
But if I'm using perl it not in the intention to use a system command to do what the perl module
is supposed to allow me to do.
Is there something wrong whith this option ?
(I also include a test image).
Thanks a lot for help.
Marc GREEN
Here is my code :
I'd like to allow upuloading pictures. But to save the disk space I want to resize the pictures
to have only picture 640x480.
Please find here included a test script about resizing.
My problem is : I can use convert from withing that script and it gives a clear sharp image.
but all the different possibilities of perlMagick Resize are just giving a blurred image.
But if I'm using perl it not in the intention to use a system command to do what the perl module
is supposed to allow me to do.
Is there something wrong whith this option ?
(I also include a test image).
Thanks a lot for help.
Marc GREEN
Here is my code :
Code: Select all
#!/usr/bin/perl -w
#
# Nom : upload_galerie_multi.plx
# But : Galerie(s) photo(s) programme pour uploader
# Ecrit par : Marc GREEN
# Date création : 20/02/2007 Version : 0.1
# Génération de la page (élémmentaire) par CGI
# Version/revision :
#
# use Carp;
use CGI qw/:standard/;
#
# The purpose of the pragma is to prohibit unsafe use of variables, symbolic
# references and barewords
# Before using a variable you'll need to declare it using "my" keyword
use strict;
#
# Pour utilisation de imagemagick
#
use Image::Magick;
# use Image::Info qw(image_info);
my $image_tmp;
my $status;
my $width;
my $height;
my $size;
my $format;
my $x_scale;
my $x_size;
my $y_scale;
my $y_size;
my $scale;
my $new_x;
my $new_y;
my @filters;
my $filter;
my $blur;
$x_size = 100;
$y_size = 150;
my $image;
my $entry;
my @photos_disponibles;
# my %galeries_disponibles;
my $photo_a_reduire;
my $photo_in;
my $photo_out;
my $geometry; # Pour redimensionnement des images
$image_tmp = Image::Magick->new();
@photos_disponibles = qx{ls *.jpg};
chomp @photos_disponibles;
@filters = qw{Point Box Hermite Hanning Hamming Blackman Gaussian Triangle Quadratic Cubic Catrom Mitchell Lanczos Bessel Sinc};
foreach ( @photos_disponibles ) {
# For every picture in the list apply all possible filters
foreach $filter (@filters){
print "Traitement de $_\n";
$image_tmp = Image::Magick->new();
$status = $image_tmp->Read($_);
if ( $status ) {
print "Erreur de lecture : $status \n";
}
($width, $height, $size, $format) =
$image_tmp->Ping("$_");
$x_scale = $x_size / $width;
$y_scale = $y_size / $height;
$scale = $x_scale;
if ( $y_scale < $scale ) {
$scale = $y_scale;
}
$new_x = int( $width * $scale + 0.5 );
$new_y = int( $height * $scale + 0.5 );
# Here I make a thumbnail image (and it is sharp after writing to file)
$status = $image_tmp->Scale( width=>$new_x, height=>$new_y);
if ( $status ) {
print "Apres_reduction : $status <br>\n";
};
print "\tEcriture de mini_$_\n";
$status = $image_tmp->Write("mini_$_");
if ( $status ) {
print "Apres_enregistrement : $status <br>\n";
}
# Getting the image information change the size depending if the image is horizontal or vertical
if ( $width > $height ) {
$geometry="640x480";
}
else {
$geometry="480x640";
}
# For every image with every filter try different "blur" values
for ($blur = 0.125; $blur <=4; $blur *= 2 ){
$status = $image_tmp->Resize(geometry=>$geometry,filter=>$filter,blur=>$blur);
if ( $status ) {
print "Apres_reduction : $status <br>\n";
};
print "\tEcriture de mid_".$filter."_".$blur."_$_\n";
$status = $image_tmp->Write("mid_".$filter."_".$blur."_$_");
if ( $status ) {
print "Apres_enregistrement : $status <br>\n";
}
# Here none of the resize images are sharp ==> unusable.
}
}
($photo_a_reduire = $_ ) =~ s/ /\ /g;
print "Redution de $photo_a_reduire\n";
`convert $photo_a_reduire -resize 640x480 converted_$photo_a_reduire`;
# This one gives a great quality image.
}