Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

ImageMagik & Perl::Magik, defaults?

by Anonymous Monk
on Apr 25, 2011 at 19:28 UTC ( #901239=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have just started trying to use ImageMagik and hope to use Perl::Magik. My current issue is trying to figure out how to go from using the ImageMagik command line tool "convert" to using the Perl::Magik functions. Specifically, I can do the following using the "convert" command line tool:

convert original.jpg -strip -density 72x72 -resample 72x72 -filter Lanczos -resize 200x200 cnv002.jpg 

and the result looks as good as rescaling the same image using Gimp. If I try to do the same things using Perl::Magik the result is very blurry. What "default" values is "convert" using? The blurry Perl code I have been trying is:

        $IM = Image::Magick->new; 
        $IM->Read($original) && 
            die __LINE__ . ": Could not do initial read on $original: $!"; 
        $IM->Strip; 
        $IM->Set(units => 'PixelsPerInch'); 
        $IM->Set(quality => 100); 
        $IM->Resample(geometry => "72x72", 
                      filter   => 'Lanczos'); 
        $IM->Resize(geometry => $fileSizes->{'hn'}->{width} ."x". 
                                $fileSizes->{'hn'}->{height}, 
                    filter   => 'Lanczos'); 
        $tmp = "$dir/hn.jpg"; 
        $IM->Write(filename=>$tmp, 
                   compression=>'None') && 
            die __LINE__ . ": Could not write to $tmp: $!"; 

I have tried a few other combinations and permutations of functions and settings but I can not duplicat ther command line results. Ideas? Pointers?

Replies are listed 'Best First'.
Re: ImageMagik & Perl::Magik, defaults?
by gam3 (Curate) on Apr 25, 2011 at 20:11 UTC
    Have you tried adding density to the arguments?
    $IM->Resample(density => "72x72", geometry => "72x72", filter => 'Lanczos');
    -- gam3
    A picture is worth a thousand words, but takes 200K.

      Thanks for the idea. I just did try it and I see no difference. I also tried your idea but dropped the "geometry". No joy.

Re: ImageMagik & Perl::Magik, defaults?
by Anonymous Monk on Apr 26, 2011 at 03:20 UTC
    I thought adding
    -debug "All" -log "%d %f %e " or -debug "Coder,Policy" -log "%d %f %e "
    Would help you duplicate the calls convert makes, but it is not so helpful on my version (ImageMagick 6.5.6-5 2009-09-25 Q16 OpenMP)
    Policy IsRightsAuthorized Domain: Path; rights=Read; pattern +="somethumb.jpg" ... Policy IsRightsAuthorized Domain: Coder; rights=Read; patter +n="JPEG" ... Policy IsRightsAuthorized Domain: Path; rights=Read; pattern +="somethumb.jpg" ... Coder ReadJPEGImage Interlace: nonprogressive Coder ReadJPEGImage Data precision: 8 Coder ReadJPEGImage Geometry: 105x78 Coder JPEGSetImageQuality Quality: 75 Coder JPEGSetImageSamplingFactor Colorspace: RGB Coder JPEGSetImageSamplingFactor Sampling Factors: 2x2,1x1,1 +x1 Policy IsRightsAuthorized Domain: Coder; rights=Write; patte +rn="JPG" ... Policy IsRightsAuthorized Domain: Path; rights=Write; patter +n="cnv002.jpg" ... Coder WriteJPEGImage Image resolution: 72,72 Coder WriteJPEGImage Interlace: non-progressive Coder WriteJPEGImage Quality: 75 Coder WriteJPEGImage Input sampling-factors=2x2,1x1,1x1 Coder WriteJPEGImage Storage class: DirectClass Coder WriteJPEGImage Depth: 8 Coder WriteJPEGImage Number of colors: unspecified Coder WriteJPEGImage JPEG data precision: 8 Coder WriteJPEGImage Image colorspace is RGB Coder WriteJPEGImage Sampling factors: 2x2,1x1,1x1
Re: ImageMagik & Perl::Magik, defaults?
by zentara (Archbishop) on Apr 26, 2011 at 14:25 UTC
    Hi, yeah some of the conversions from c-lib function to Perl are not obvious. I always go to the Perl-Magick API page, and go thru the method list and see what I'm looking for. Then write some sample code for that method, and see if errors get thrown. It often leads to the correct syntax.

    Also the mail archives from the maillists often contain examples of correct usage for Perl. See ImageMagick

    The ImageMagick maillist is pretty good.


    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://901239]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2021-03-07 19:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (122 votes). Check out past polls.

    Notices?