Imagp setGravity php function does not work with compositeImage () function

I am using the php Imagick class for a project

I am trying to create an image that changes the gravity of an image

What I mean, I want the composite image of the target to be in the middle or in the upper center.

I use

....
$imageOrg->setGravity(imagick::GRAVITY_CENTER); //I wrote this for an example, position will be set by the visitor
$imageOrg->compositeImage($over, Imagick::COMPOSITE_DEFAULT, 0, 0);
....

But the functions setGravity () or setImageGravity () do not work.

Please, help!

+5
source share
1 answer
$imageOrg->compositeImage($over, Imagick::COMPOSITE_DEFAULT, (((($imageOrg->getImageWidth()) - ($over->getImageWidth())))/2), (((($imageOrg->getImageHeight()) - ($over->getImageHeight())))/2));

Basically, what you do is set the left-side offset of your image to the width of the container, minus the width of the composite image, divided into two parts, which compensates for this enough to center horizontally. Then you do the same for the height, and it is centered vertically.

, , Gravity , : ,

+8

All Articles