使用 PHP 旋转 PNG 图像。如何去除原稿周围的黑线?
我正在使用 PHP 旋转具有透明背景的 PNG 图像。但无论我如何尝试,原始图像周围仍然存在一些黑线。
怎样去掉黑线。其他一切都很好。图像是透明的,图像被旋转,新的角也是透明的。只是原始正方形(旋转后)周围的黑线让我很恼火。
我使用这段代码:
$angle = -100;
header('Content-type: image/png');
$image = 'http://mapning.com/img/plane.png';
$file = imagecreatefrompng($image);
$rotate = imagerotate($file, $angle, 0);
imageSaveAlpha($rotate, true);
ImageAlphaBlending($rotate, false);
$transparentColor = imagecolorallocatealpha($rotate, 200, 200, 200, 127);
imagefill($rotate, 0, 0, $transparentColor);
imagepng($rotate);
我在这里找到了答案:
https://www .php.net/manual/en/function.imagerotate.php#47985
I am using PHP to rotate an PNG image, with a transparant background. But whatever I try, there are still some black lines around the original image.
How do I remove the black lines. Everything else works fine. The image is transparant, the image is rotated, the new corners are also transparant. Just the black lines around the original square (which is rotated) are annoying me.
I use this code:
$angle = -100;
header('Content-type: image/png');
$image = 'http://mapning.com/img/plane.png';
$file = imagecreatefrompng($image);
$rotate = imagerotate($file, $angle, 0);
imageSaveAlpha($rotate, true);
ImageAlphaBlending($rotate, false);
$transparentColor = imagecolorallocatealpha($rotate, 200, 200, 200, 127);
imagefill($rotate, 0, 0, $transparentColor);
imagepng($rotate);
I found my answer here:
https://www.php.net/manual/en/function.imagerotate.php#47985
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为最好使用 imagick
这里是 PHP 的扩展
或者如果您想要使用 GD,请参见这里
https://www.php.net/manual/en/function。 imagerotate.php#46338
I think better use imagick
Here is an extension for PHP
Or if you want with GD see here
https://www.php.net/manual/en/function.imagerotate.php#46338