Page 1 of 1

Crop() does not gravitate?

Posted: 2009-12-06T01:42:15-07:00
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"?)

Re: Crop() does not gravitate?

Posted: 2009-12-06T08:59:56-07:00
by magick
We'll have a patch for the problem you reported by sometime tomorrow. Thanks.

Re: Crop() does not gravitate?

Posted: 2010-01-10T21:46:15-07:00
by Randolf
I've noticed that ->Extent seems to ignore the "center" attribute as well.

Re: Crop() does not gravitate?

Posted: 2012-01-26T04:16:27-07:00
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;

Re: Crop() does not gravitate?

Posted: 2012-01-26T04:19:28-07:00
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.

Re: Crop() does not gravitate?

Posted: 2012-03-03T06:28:55-07:00
by Bugsy
Still no fix for this?

Re: Crop() does not gravitate?

Posted: 2012-05-23T01:51:00-07:00
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...