I’m having some real difficulties setting the gravity of an image in Imagick.
I’ve managed to set the gravity of an ImaickDraw object but I’ve not been successful setting it in a Imagick object.
Below is the basic code I’m using that the moment. I’ve just used the same as for ImagickDraw but obviously it isn’t working.
$rating = new Imagick("ratings/" . $rating . ".png");
$rating->setGravity (Imagick::GRAVITY_SOUTH);
$im->compositeImage($rating, imagick::COMPOSITE_OVER, 20, 20);
Any ideas how to set the gravity for an exisiting image rather than a draw object?
Thanks!
In your case
setGravitymethod should be applied to$imobject. But anyways it looks like the gravity affects only ImagickDraw objects, inserted withdrawImage, and there’s no way to put an image in a draw like you can do with ImageMagick commands.So there’s two ways to do this:
1st. If your hosting allows functions
shell_execorexec, you can run a command like.2nd. Otherwise, you can calculate position of the image being placed on the base image and use
compositeImage