Page 1 of 1

Translate Imagemagick command to Imagick

Posted: 2018-12-27T22:45:41-07:00
by rinsad
I have the following imagemagick command line options

-gravity center -background none -extent ${wbg}x${hbg}
which I replicated with the following Imagick code piece but not producing the same result.

$tmpA12->setImageGravity(imagick::GRAVITY_CENTER);

$tmpA12->setImageBackgroundColor(new \ImagickPixel("transparent"));

$tmpA12->extentImage($wbg, $hbg, 0,0);
I believe the setImageGravity is not acting upon the image or the offset 0,0 needs the right value. I am bit stuck here please help me on it

Re: Translate Imagemagick command to Imagick

Posted: 2018-12-27T22:56:53-07:00
by fmw42
I just posted to stack overflow. See my answer there.

My guess is that extentImage, like cropImage, does not support gravity settings. You will have to compute the center offset from the northwest corner, like you have to in cropImage and use the x,y offsets built into extentImage. However, before you give up on gravity, try http://us3.php.net/manual/en/imagick.setgravity.php (setGravity) rather than setImageGravity.

Re: Translate Imagemagick command to Imagick

Posted: 2018-12-27T23:02:15-07:00
by rinsad
setGravity doesn't work either. Could you give me some tips on computing the offset from the northwest to the image area

Re: Translate Imagemagick command to Imagick

Posted: 2018-12-28T10:12:39-07:00
by fmw42
Did you not do that for cropImage? It is the same for extentImage. See the comments section with switch code for doing that at http://us3.php.net/manual/en/imagick.cropimage.php