php imagick setGravity函数不能与compositeImage()函数一起使用 [英] php imagick setGravity function doesn't work with compositeImage() function

查看:404
本文介绍了php imagick setGravity函数不能与compositeImage()函数一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用php Imagick类进行项目

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

我使用

....
$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);
....

但是setGravity()或setImageGravity()函数都没有工作。

But either setGravity() or setImageGravity() functions don't work.

请帮助!

推荐答案

$imageOrg->compositeImage($over, Imagick::COMPOSITE_DEFAULT, (((($imageOrg->getImageWidth()) - ($over->getImageWidth())))/2), (((($imageOrg->getImageHeight()) - ($over->getImageHeight())))/2));

基本上你正在做的是将图像的左偏移量设置为容器的宽度,减去你的合成图像的宽度除以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

这篇关于php imagick setGravity函数不能与compositeImage()函数一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆