I'm using php Imagick class for a project
I try to composite an image changing the gravity of the image
What I mean is, I want to composite the target image to middle or to the top 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 either setGravity() or setImageGravity() functions don't work.
Please help!
Imagick is a PHP extension to create and modify images using the ImageMagick library. There is also a version of Imagick available for HHVM. Although the two extensions are mostly compatible in their API, and they both call the ImageMagick library, the two extensions are completely separate code-bases.
ImageMagick is a software suite that creates, edits, composes, or converts bitmap images. It can read and write images in over 200 formats. We may use ImageMagick commands to resize, rotate, and transform images, adjust image colors, apply various special effects, or draw text, lines, and shapes.
Imagick and GD are popular image optimization libraries in PHP applications. While they both perform many of the same actions, they operate a bit different from each other and offer different benefits. Overall, these two libraries are used for: Resizing/cropping images. Modifying the contents of an image.
$imageOrg->compositeImage($over, Imagick::COMPOSITE_DEFAULT, (((($imageOrg->getImageWidth()) - ($over->getImageWidth())))/2), (((($imageOrg->getImageHeight()) - ($over->getImageHeight())))/2));
Basically what you're doing is setting the left offset of your image to your Container's width, minus your composite image's width, divided by two, this will offset it enough to center horizontally. Then you do the exact same thing for the height, and it's centered vertically.
I had the same type of problem, best I can figure Gravity settings only apply to Drawing contexts, ie: Text, annotations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With