[英]PHP GD: Crop polygon: Works with some images, with some not
我想裁剪从Google Maps Static API中保存的图像的多边形(我有一个透明区域)。 然后,我创建了第二个图像,保存了该图像,并在其上尝试了相同的脚本,但是不同之处在于,对第二个尝试的图像没有影响/更改,但是它是相同的图像。 也许是PHP错误? 我正在使用PHP 5.3.3。
<?php
$image = imagecreatefrompng('map.png');
$image2 = imagecreatefrompng('map2.png');
$black = imagecolorallocatealpha($image, 0, 0, 0, 127);
$black2 = imagecolorallocatealpha($image2, 0, 0, 0, 127);
imagefilledpolygon($image, array(0,0, 20,20, 0,20), 3, $black);
imagefilledpolygon($image2, array(0,0, 20,20, 0,20), 3, $black2);
header('Content-Type: image/png');
imagepng($image);
#imagepng($image2);
?>
图片1
图片2:
我找到了解决方案:您必须为图像设置imagealphablending 和 imagesavealpha设置,以使此透明度起作用。 还存在这些图像具有不同位的问题。 工作映像为8位,而不工作映像为24位。
imagealphablending($image2, false);
imagesavealpha($image2, true);
此评论对我有很大帮助: http : //www.php.net/manual/zh/function.imagecreatefrompng.php#47083
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.