Crop() does not gravitate?

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

Crop() does not gravitate?

Post by WindedHero »

Try:

Code: Select all

$image->Crop(Gravity=>'Center', height=>'100', width=>'100');
... it fails to gravitate. It only crops from top left regardless of the gravity setting. Any ideas?

I've also tried this one and it had failed:

Code: Select all

$image->Transform(crop=>$width.'x'.$height.'+0+0', gravity=>'Center');
This is with:
ActivePerl 5.10.1 build 1006
ImageMagick (dll) 6.5.8 Q16
Apache 2.2.14 (32-bit Windows 7)

#####Update
I've found a quirky work-around. For some reason I have to overwrite the variable?
This works:

Code: Select all

$image = $image->Transform(crop=>$height.'x'.$height.'+0+0', gravity=>'Center');
Adding $image = $image seems kind of silly. Is this a bug or what?
Also, Crop() still doesn't work with gravity when trying this quirky method.
If it helps, I've also pulled this oddity from my server's error.log:

Code: Select all

Can't locate object method "GetAttribute" via package "Exception 410: unrecognized option `gravity' @ Magick.xs/XS_Image__Magick_Mogrify/6953" (perhaps you forgot to load "Exception 410: unrecognized option `gravity' @ Magick.xs/XS_Image__Magick_Mogrify/6953"?)
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Crop() does not gravitate?

Post by magick »

We'll have a patch for the problem you reported by sometime tomorrow. Thanks.
User avatar
Randolf
Posts: 19
Joined: 2007-10-08T20:58:27-07:00
Location: Beautiful British Columbia, Canada

Re: Crop() does not gravitate?

Post by Randolf »

I've noticed that ->Extent seems to ignore the "center" attribute as well.
snoopy
Posts: 2
Joined: 2012-01-26T04:11:25-07:00
Authentication code: 8675308

Re: Crop() does not gravitate?

Post by snoopy »

This is still broken in the latest version. I'm using the latest ImageMagick which I recompiled for the Mac. PerlMagick is from cpan. 'gravity' will not work.

Code: Select all

my $image = $_[0]{IMGOBJ}->clone();
$image->Set(quality=>85);
$image->Set(magick => 'JPEG');
my $w = 85; my $h = 100;

## resize with ratio lock and do not go below the width/height we are after. Pain in the arse code.
if (($image->Get('columns')/$image->Get('rows')) > ($w/$h)) { $image->Resize(height=>$h, width=>sprintf("%.0f",($image->Get('columns')/($image->Get('rows')/$h)))); }
else { $image->Resize(height=>sprintf("%.0f",($image->Get('rows')/($image->Get('columns')/$w))), width=>$w); }
## now we'll crop the bits outside the size we want
$image->Crop(height=>$h, width=>$w, gravity=>'Center');
my $x = $image->Write($SETTINGS{systemroot}.'/objects/main/users/'.$_[0]{USER}.'/photos/thumbnails/work.jpg');
die($x) if $x;
snoopy
Posts: 2
Joined: 2012-01-26T04:11:25-07:00
Authentication code: 8675308

Re: Crop() does not gravitate?

Post by snoopy »

I can confirm that this works;

Code: Select all

$image = $image->Transform(crop=>$h.'x'.$w.'+0+0', gravity=>'Center');
So it appears whatever fix was implemented was deleted.
Bugsy
Posts: 1
Joined: 2012-03-03T06:27:02-07:00
Authentication code: 8675308

Re: Crop() does not gravitate?

Post by Bugsy »

Still no fix for this?
NVisme
Posts: 1
Joined: 2012-05-23T01:47:32-07:00
Authentication code: 13

Re: Crop() does not gravitate?

Post by NVisme »

So, after a little research I found that you can crop an image from the center using the crop command. You just need to use the Set function first to set the gravity to center rather than including it in the Crop function.

Example:

Code: Select all

$image->Set(Gravity=>'Center');
$image->Crop(geometry=>'1068x1425');
Hope this helps some of you looking for an answer...
Post Reply