php imagick setGravity function doesn't work with compositeImage() function

冷暖自知 提交于 2019-12-10 13:09:41

问题


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!


回答1:


$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



来源:https://stackoverflow.com/questions/11921433/php-imagick-setgravity-function-doesnt-work-with-compositeimage-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!