convert resize VS perlMagick resize

PerlMagick is an object-oriented Perl interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning PerlMagick.
Post Reply
CptFantastic

convert resize VS perlMagick resize

Post by CptFantastic »

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 :

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.

}
twotone

Re: convert resize VS perlMagick resize

Post by twotone »

I'm having exactly the same result.

In my perl script if I resize like this:

Code: Select all

$image->Resize(geometry=>'720x486!');
The result is blurry. If I execute the system command

Code: Select all

$result = `convert $file -resize 720x486! $out_name`;
The resulting picture is sharp.

Why is perlmagick resize blurry?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert resize VS perlMagick resize

Post by fmw42 »

I suspect because the command line resize has been updated and the perl code not. see recent topics in the Developers forum about changes to resize and to distort SRT
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: convert resize VS perlMagick resize

Post by anthony »

They both should be using the same core library code, unless the perl magick is using a different IM library! Did you upgrade Perl Magick with ImageMagick?

the resize code itself has not changed for a VERY VERY long time. It was distort that changed dramatically and recently.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply