Translate Imagemagick command to Imagick

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
rinsad
Posts: 2
Joined: 2018-12-27T10:36:14-07:00
Authentication code: 1152

Translate Imagemagick command to Imagick

Post by rinsad » 2018-12-27T22:45:41-07:00

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

User avatar
fmw42
Posts: 25256
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Translate Imagemagick command to Imagick

Post by fmw42 » 2018-12-27T22:56:53-07:00

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.

rinsad
Posts: 2
Joined: 2018-12-27T10:36:14-07:00
Authentication code: 1152

Re: Translate Imagemagick command to Imagick

Post by rinsad » 2018-12-27T23:02:15-07:00

setGravity doesn't work either. Could you give me some tips on computing the offset from the northwest to the image area

User avatar
fmw42
Posts: 25256
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Translate Imagemagick command to Imagick

Post by fmw42 » 2018-12-28T10:12:39-07:00

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

Post Reply