Page 1 of 1

No repage in PerlMagick Crop()?

Posted: 2006-12-11T07:34:38-07:00
by rmabry
Is it possible that there is no repage available in PerlMagick's Crop()?

I do not see a repage operator in the PerlMagick doc, so I tried forcing the issue using the geometry string (!) á la the command line.

Code: Select all

use Image::Magick;

$image1 = new Image::Magick;

$image1->Read('logo:');
$image2 = $image1->Clone();

$image1->Crop("300x200+50+75");
$image1->Write(filename=>'logocrop1.png');

$image2->Crop("300x200+50+75!");
$image2->Write(filename=>'logocrop2.png');
Executing the above gives two files. But identify shows the trouble - the second file is not +repaged:

Code: Select all

> identify logocrop1.png

logocrop1.png PNG 300x200 640x480+50+75 DirectClass 16-bit  31.3926kb

> identify logocrop2.png

logocrop2.png PNG 300x200 640x480+50+75 DirectClass 16-bit 31.3926kb
The command line versions, of course, are fine:

Code: Select all

> convert logo: -crop 300x200+50+75 logocrop1.png

> convert logo: -crop 300x200+50+75! logocrop2.png

>identify logocrop1.png

logocrop1.png PNG 300x200 640x480+50+75 DirectClass 16-bit 31.3926kb

>identify logocrop2.png

logocrop2.png PNG 300x200 300x200+0+0 DirectClass 16-bit 31.373kb
So how do I (or can I) force a repage in PerlMagick?

Rick

Posted: 2006-12-11T07:44:19-07:00
by magick
  • $image->Set( page=>'0x0+0+0' );
is equivalent to the +repage command-line option.

Posted: 2006-12-11T08:16:58-07:00
by rmabry
magick wrote:
  • $image->Set( page=>'0x0+0+0' );
is equivalent to the +repage command-line option.


Fabulous, Mr. Wizard!

I appreciate your speedy replies but worry that you never sleep.

Rick

Posted: 2006-12-11T16:56:20-07:00
by rmabry
magick wrote:
  • $image->Set( page=>'0x0+0+0' );
is equivalent to the +repage command-line option.


Now I'm just curious - shouldn't / couldn't the commandline-style geometry work with Crop(), if for no other reason than to make code a bit more compact (and maybe faster)? Or perhaps another option to Crop() to force a repage? I'll probably be calling Set( page=>'0x0+0+0' ) after every crop, which is fine but seems excessive. Of course I can write a sub, but still...

Rick

Posted: 2006-12-11T17:24:41-07:00
by magick
Operations are typically more atomic with an API than on the command-line. The burden is on the programmer. In the case of PerlMagick, since its object oriented, you could always write a class to support crop with repage.