为什么旋转图像时会出现黑色边框? PHP GD
此代码使用 GD 生成两张图像并旋转其中一张。当我旋转图像时,黑色边框开始出现。有人知道如何解决这个问题吗?
<?php
$im = imagecreatetruecolor(300, 400);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 000, 000, 000);
$black1 = imagecolorallocate($im, 001, 001, 001);
$grey = imagecolorallocate($im, 230, 230, 230);
$font_file = './arial.ttf';
$rotate=45;
imagefilledrectangle($im, 0, 0, 300, 400, $black);
imagefilledrectangle($im, 1, 1, 298, 398, $grey);
imagefilledrectangle($im, 49, 69, 251, 271, $black);
imagefilledrectangle($im, 50, 70, 250, 270, $white);
imagefttext($im, 13, 0, 90, 30, $black, $font_file, "Wind Direcction");
$source=imagecreatetruecolor(100, 100);
imagefilledrectangle($source, 0, 0, 100, 100, $white);
$values = array(
20, 30, // Point 1 (x, y)
50, 0,
80, 30,
65, 30,
65, 100,
35, 100,
35, 30 // Point 7 (x, y)
);
imagefilledpolygon($source, $values, 7, $black1);
$asd=imagerotate($source, $rotate, 0);
imagecolortransparent($asd, $black);
imageantialias($asd, true);
$insert_x = imagesx($asd);
$insert_y = imagesy($asd);
if($rotate==0 || $rotate==90 || $rotate==180 || $rotate==270){
imagecopymerge ( $im , $asd , 100 , 130 , 0 , 0 , $insert_x , $insert_y , 100 );
}
if($rotate==45 || $rotate==135 || $rotate==225 || $rotate==315){
imagecopymerge ( $im , $asd , 85 , 110 , 0 , 0 , $insert_x , $insert_y , 100 );
}
imageantialias($im, true);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
This code generates two images using GD and rotates one of them. When I rotate the image black borders begin to appear. Anyone have an idea of how to resolve this?
<?php
$im = imagecreatetruecolor(300, 400);
$white = imagecolorallocate($im, 255, 255, 255);
$black = imagecolorallocate($im, 000, 000, 000);
$black1 = imagecolorallocate($im, 001, 001, 001);
$grey = imagecolorallocate($im, 230, 230, 230);
$font_file = './arial.ttf';
$rotate=45;
imagefilledrectangle($im, 0, 0, 300, 400, $black);
imagefilledrectangle($im, 1, 1, 298, 398, $grey);
imagefilledrectangle($im, 49, 69, 251, 271, $black);
imagefilledrectangle($im, 50, 70, 250, 270, $white);
imagefttext($im, 13, 0, 90, 30, $black, $font_file, "Wind Direcction");
$source=imagecreatetruecolor(100, 100);
imagefilledrectangle($source, 0, 0, 100, 100, $white);
$values = array(
20, 30, // Point 1 (x, y)
50, 0,
80, 30,
65, 30,
65, 100,
35, 100,
35, 30 // Point 7 (x, y)
);
imagefilledpolygon($source, $values, 7, $black1);
$asd=imagerotate($source, $rotate, 0);
imagecolortransparent($asd, $black);
imageantialias($asd, true);
$insert_x = imagesx($asd);
$insert_y = imagesy($asd);
if($rotate==0 || $rotate==90 || $rotate==180 || $rotate==270){
imagecopymerge ( $im , $asd , 100 , 130 , 0 , 0 , $insert_x , $insert_y , 100 );
}
if($rotate==45 || $rotate==135 || $rotate==225 || $rotate==315){
imagecopymerge ( $im , $asd , 85 , 110 , 0 , 0 , $insert_x , $insert_y , 100 );
}
imageantialias($im, true);
header('Content-Type: image/png');
imagepng($im);
imagedestroy($im);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来图像的默认颜色是白色:
而透明度是黑色:
尝试将透明度设置为白色。
Looks like the default color of your image is white:
And your transparency is black:
Try making the transparency white.