设置后,Imagick无法反映重力 [英] Imagick not reflects the gravity once it is set
问题描述
我正在尝试翻译下面的Imagemagick命令行代码
I am trying to translate the following piece of Imagemagick command line code
convert tmpI.mpc -gravity center -crop ${ww}x${hc}+0+0 +repage
如下
$tmpIC->setGravity(imagick::GRAVITY_CENTER);
$tmpIC->cropImage($ww, $hc, 0, 0);
$tmpIC->setImagePage($tmpIC->getImageWidth(), $tmpIC->getImageHeight(), 0, 0);
但是设置或不设置重力没有区别.请告诉我我的这段代码有什么问题
but setting or not setting the gravity makes no difference. Please tell me what is wrong with the piece of code I have
裁剪前图像的宽度和高度为
Width and Height of the image before cropping are
tmpIC->getImageWidth() = 479
tmpIC->getImageHeight() = 599
ww和hc的值是
ww=479
hc=479
以及裁剪后图像的宽度和高度如下
and the width and height of the image after cropping are as follows
tmpIC->getImageWidth() = 479
tmpIC->getImageHeight() = 479
推荐答案
在Imagick中,并非所有ImageMagick命令都可以直接转换为相同的命名命令.
Not all of the ImageMagick commands can be converted directly to the same named commands in Imagick.
在您的情况下,引力命令的映射效果不是很好-但是您可以通过一个单独的cropImage函数调用来完成将图像裁剪到中心的相同效果:
In your case, the gravity command doesn't map very well - but the same effect of cropping the image to the centre can be done by yourself in a single cropImage function call:
$tmpIC->cropImage(
$ww,
$hc,
$startX = ($tmpIC->getImageWidth() - $ww) / 2,
$startY = ($tmpIC->getImageHeight() - $hc) / 2
);
这篇关于设置后,Imagick无法反映重力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!