Page 1 of 1

PerlMagick distort() syntax

Posted: 2008-04-12T12:10:58-07:00
by Ryland
When I use the following command line:

Code: Select all

convert checks.png -matte -virtual-pixel transparent -distort Perspective "0,0,25,25 0,90,0,90 90,0,70,25 90,90,90,65" checks_distort.png
It distorts the image correctly, but when I use the same parameters in PerlMagick:

Code: Select all

use Image::Magick;

$checks = Image::Magick->new;
$checks->Set(size=>"90x90",matte=>"True");
$checks->Read('checks.png');

$checks->Distort(virtual-pixel=>"transparent", distort=>"Perspective", points=>"0,0,25,25 0,90,0,90 90,0,70,25 90,90,90,65");

$checks->Write("PNG24:checks_distort.png");
It returns the source image unchanged. What am I doing wrong?

I'm using ActivePerl 5.8.8 and ImageMagick 6.3.6 Q16 under Windows XP Pro.

Re: PerlMagick distort() syntax

Posted: 2008-04-12T16:44:59-07:00
by magick
Use an array instead of a string: points=>[0,0,25,25 0,90,0,90 90,0,70,25 90,90,90,65].

Re: PerlMagick distort() syntax

Posted: 2008-04-12T17:26:35-07:00
by Ryland
magick wrote:Use an array instead of a string: points=>[0,0,25,25 0,90,0,90 90,0,70,25 90,90,90,65].
That causes a bunch of syntax errors. I replaced the spaces in the array with commas and that got rid of the syntax errors, but then the script still didn't work.

This is one of the most frustrating things about ImageMagick for me. Why doesn't the PerlMagick API use the same parameter names and values as the command line version? I can't count the number of times I've had this kind of problem.

Re: PerlMagick distort() syntax

Posted: 2008-04-12T18:05:52-07:00
by magick
This works for us (we're using ImageMagbick 6.4.0-7):
  • $image->Distort('virtual-pixel'=>"transparent", type=>"Perspective", points=>[0,0,25,25,0,90,0,90,90,0,70,25,90,90,90,65]);

Re: PerlMagick distort() syntax

Posted: 2008-04-12T18:27:25-07:00
by Ryland
I just updated my IM install to 6.4.0-6, and now it doesn't work at all:

"Can't locate Image/Magick.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at affine.pl line 3."

so apparently the PerlMagick module didn't even get installed. When I try to install it manually, it says:

"ppm install failed: The PPD does not provide code to install for this platform."

Re: PerlMagick distort() syntax

Posted: 2008-04-12T18:49:55-07:00
by Ryland
OK, I managed to get PerlMagick installed (thanks to the "PerlMagic ppm install fails on Windows 2003 server and XP" thread a few threads below this one) and now the distort works.

My point still stands, though, it's ridiculous to have different parameter names and values between the command line and the Perl API. Why use a string for the points parameter in the command line version and an array of doubles in the API? That makes no sense.

Not to mention that in the PerlMagick documentation, the parameter is just given as "double". Not string, not array of doubles, just double.

http://www.imagemagick.org/script/perl-magick.php

Re: PerlMagick distort() syntax

Posted: 2008-04-13T08:38:32-07:00
by magick
We fixed the documentation so that the points parameter for Distort() states that it expects an array of floats. Thanks.