如何完全旋转图像。不显示黑色部分
我有一个图像,我必须将该图像旋转 25 度。如果我旋转它会显示一些黑色背景。我怎样才能避免这种情况。如何使用 PHP GD 完全旋转图像而不显示黑色部分。我无法使用js进行旋转。因为我必须在旋转后将图像与另一张图像合并。任何人都有这方面的脚本,请帮助我。
I have an image I have to rotate that image 25 degree. if I rotate it shows some black background. How can I avoid that. How can I rotate image completely with out showing the black portion by using PHP GD. I cant use js for rotation. because I have to merge the image with another one after rotation. any body have the scripts for this please help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
旋转时黑色区域是不可避免的 - PHP(以及 GD)不是 Photoshop 的内容感知填充,并且不会在旋转过程中为您生成更多图片来掩盖黑色位。
您有两个选择:
做一些数学计算,计算出可以从旋转图像中切出多大的矩形以消除黑色边框(例如:旋转后的图像将小于原始图像)
放大之前的原始图像旋转,这样旋转后就可以切出与原始未旋转尺寸相匹配的矩形块。同样,需要一些数学知识。
当然,这一切都取决于您如何旋转图像。在角落旋转会导致与在图像中心旋转截然不同的结果。
The black area is unavoidable on rotation - PHP (and GD for that matter) isn't Photoshop's content-aware-fill and won't generate more picture for you during the rotation to cover up the black bits.
You've got two choices:
do some math and figure out what size of rectangle you can slice out of the rotated image to eliminate the black borders (eg: the post-rotation image will be smaller than the original)
blow up the original image prior to rotating, such that after rotating, you can slice out a rectangular chunk that matches the original non-rotated size. Again, calls for a bit of math.
Of course, this all depends on just how you're rotating the image. Rotating on a corner will lead to vastly different results than rotating on the center of the image.