PHP-Imagick:在Imagick项目上设置重力
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP-Imagick:在Imagick项目上设置重力,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1574字,纯文字阅读大概需要3分钟。
内容图文
![PHP-Imagick:在Imagick项目上设置重力](/upload/InfoBanner/zyjiaocheng/653/d5b53e14c70746139a3008578176e69d.jpg)
在Imagick中设置图像的重力时,我遇到了一些实际困难.
我已经成功设置了ImaickDraw对象的重力,但是我没有成功在Imagick对象中设置它.
以下是此刻我正在使用的基本代码.我只是使用了与ImagickDraw相同的方法,但是显然它没有用.
$rating = new Imagick("ratings/" . $rating . ".png");
$rating->setGravity (Imagick::GRAVITY_SOUTH);
$im->compositeImage($rating, imagick::COMPOSITE_OVER, 20, 20);
有什么想法如何为现有图像而不是绘图对象设置重力?
谢谢!
解决方法:
在您的情况下,setGravity方法应应用于$im对象.但是无论如何,重力似乎仅会影响到用drawImage插入的ImagickDraw对象,并且无法像使用ImageMagick命令那样将图像放入绘图中.
因此,有两种方法可以做到这一点:
1号如果您的主机允许使用shell_exec或exec函数,则可以运行类似的命令.
convert image.jpg -gravity south - draw "image Over 0,0 0,0 watermak.png" result.jpg`
2号否则,您可以计算放置在基础图像上的图像的位置,并使用CompositeImage
$imageHight = $im->getImageHeight();
$imageWith = $im->getImageWidth();
// Scale the sprite if needed.
// Here I scale it to have a 1/2 of base image's width
$rating->scaleImage($imageWith / 2, 0);
$spriteWidth = $rating->getImageWidth();
$spriteHeight = $rating->getImageHeight();
// Calculate coordinates of top left corner of the sprite
// inside of the image
$left = ($imageWidth - $spriteWidth)/2; // do not bother to round() values, IM will do that for you
$top = $imageHeight - $spriteHeight;
// If you need bottom offset to be, say, 1/6 of base image height,
// then decrease $top by it. I recommend to avoid absolute values here
$top -= $imageHeight / 6;
$im->compositeImages($rating, imagick::COMPOSITE_OVER, $left, $top);
内容总结
以上是互联网集市为您收集整理的PHP-Imagick:在Imagick项目上设置重力全部内容,希望文章能够帮你解决PHP-Imagick:在Imagick项目上设置重力所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。