Php 图像旋转导致背景变化

Php 图像旋转导致背景变化,php,image,Php,Image,我用翻转图像编写代码,然后将其旋转-60度,问题是旋转的部分背景比原始图像更暗 使用的示例图像是透明的png图像 我所做的总结 1:我做了一个白色的图层 2:使用imagecopyresampled将图像放在图层A上 3:翻转层A,旋转层A 使用的图像: 输出图像 不知道这是否是问题所在,但为什么在imagerotate中使用alpha值127?既然没有不透明性,255肯定更合适?为什么您将255^3注释为“灰色”而不是“白色”?再次尝试imageColorAllocateAlpha($fin

我用翻转图像编写代码,然后将其旋转-60度,问题是旋转的部分背景比原始图像更暗

使用的示例图像是透明的png图像

我所做的总结 1:我做了一个白色的图层 2:使用imagecopyresampled将图像放在图层A上 3:翻转层A,旋转层A

使用的图像:

输出图像


不知道这是否是问题所在,但为什么在imagerotate中使用alpha值127?既然没有不透明性,255肯定更合适?为什么您将255^3注释为“灰色”而不是“白色”?再次尝试imageColorAllocateAlpha($finala,255,255,255)而不是imageColorAllocateAlpha($finala,255,255,255)。可能是旋转图像外部的区域的不透明度低于1,然后,合并图像时,不透明度较小的部分看起来比旋转图像亮。还有,原始图像中的白色真的是纯白色吗?我还没查过。请试着写出句子。编辑:啊,你的原始图像确实不透明度。嗯,我需要检查一些东西。另外:你的原始图像的背景色是完全不透明的。尝试使用imageColorAllocateAlpha($finala,255,255,0)来匹配它。尝试使用imageColorAllocateAlpha($finala,255,255,255,0)仍然存在相同的问题。在您链接的JPG中,背景之间没有差异-您能给我们一些具有alpha值的输出吗?我想最好是巴布亚新几内亚。
$image1=imagecreatefrompng($_GET["v1"]);
$image2=imagecreatefrompng($_GET["v1"]);
//filter_opacity( $image1, 25 );

$w=imagesx($image1);
$h=imagesy($image1);
$finala = imagecreatetruecolor($w, $h);
$finalb = imagecreatetruecolor($w, $h);
$finalc = imagecreatetruecolor($w, $h);

$backgroundColora = imagecolorallocate($finala, 255,255,255); // white bg
$backgroundColorb = imagecolorallocate($finalb, 255,255,255); // white bg
$backgroundColorc = imagecolorallocate($finalc, 255,255,255); // white bg

imagefill($finala, 0, 0, $backgroundColora);
imagefill($finalb, 0, 0, $backgroundColorb);
imagefill($finalc, 0, 0, $backgroundColorc);


$percent = 0.583;
$new_width = $w * $percent;
$new_height = $h * $percent;
$wshift = $w/8.5;
$hshift = $h/2.5;


imagecopyresampled($finala, $image2,$wshift,$hshift,0,0, $new_width, $new_height, $w, $h);
imagecopyresampled($finalc, $image2,$wshift,$hshift,0,0, $new_width, $new_height, $w, $h);
imagecopyresampled($finalb, $finalc,$w*0.3,$h*0.3,0,0, $w*0.6, $h*0.6, $w, $h);
imageflip($finala, IMG_FLIP_HORIZONTAL );


$finala = imagerotate($finala, -60, imageColorAllocateAlpha($finala, 255, 255, 255, 127));
imagecopyresampled($finalb, $finala,-$w*0.1,-$h*0.1,0,$h*0.20, $new_width, $new_height, $w, $h);
header('Content-Type: image/jpeg');
imagejpeg($finalb);
imagedestroy($finala);
imagedestroy($image2);
imagedestroy($image1);
imagedestroy($final);