Imagick not reflects the gravity once it is set

喜你入骨 提交于 2020-01-06 07:16:06

问题


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

as follows

$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

And the values of ww and hc are

ww=479
hc=479

and the width and height of the image after cropping are as follows

tmpIC->getImageWidth() = 479
tmpIC->getImageHeight() = 479

回答1:


Not all of the ImageMagick commands can be converted directly to the same named commands in Imagick.

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


来源:https://stackoverflow.com/questions/53740417/imagick-not-reflects-the-gravity-once-it-is-set

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