PHP GD透明度不适用于iPhone

PHP GD透明度不适用于iPhone,php,iphone,image,gd,Php,Iphone,Image,Gd,我正在使用代码创建一个带有PHPGD的图像,它需要一个完全透明的背景。当我创建它时,它在浏览器中显示良好,但在我的iPhone应用程序中显示不好。我不知道为什么,但在我的iPhone中,它以黑色显示所有的透明度。这似乎是GD问题,因为当我将GD图像加载到web编辑器并重新导出时,它在我的iPhone应用程序中显示良好。是否有一种特殊的方法可以从GD或其他什么导出png图像,或者这是某种bug?代码如下: $filename = "./me.jpg"; $image_s = imagecreat

我正在使用代码创建一个带有PHPGD的图像,它需要一个完全透明的背景。当我创建它时,它在浏览器中显示良好,但在我的iPhone应用程序中显示不好。我不知道为什么,但在我的iPhone中,它以黑色显示所有的透明度。这似乎是GD问题,因为当我将GD图像加载到web编辑器并重新导出时,它在我的iPhone应用程序中显示良好。是否有一种特殊的方法可以从GD或其他什么导出png图像,或者这是某种bug?代码如下:

$filename = "./me.jpg";

$image_s = imagecreatefromjpeg($filename);

list($current_width, $current_height) = getimagesize($filename);

$left = isset($_GET['pl']) ? abs($_GET['pl']) : 0;
$top = isset($_GET['pt']) ? abs($_GET['pt']) : 0;

$width = isset($_GET['cs']) ? abs($_GET['cs']) : 65;
$height = isset($_GET['cs']) ? abs($_GET['cs']) : 65;

$canvas = imagecreatetruecolor($width, $height);
$current_image = imagecreatefromjpeg($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);

$newwidth = 65;
$newheight = 65;

$image = imagecreatetruecolor($newwidth, $newheight);
imagealphablending($image, true);
imagecopyresampled($image, $canvas, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

$mask = imagecreatetruecolor($newwidth, $newheight);

$transparent = imagecolorallocate($mask, 255, 255, 255);
imagecolortransparent($mask, $transparent);

imagefilledellipse($mask, $newwidth / 2, $newheight / 2, $newwidth, $newheight, $transparent);

$red = imagecolorallocate($mask, 0, 0, 0);
imagecopymerge($image, $mask, 0, 0, 0, 0, $newwidth + 10, $newheight + 10, 100);
imagecolortransparent($image, $red);
imagefill($image,0,0, $red);

header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
imagedestroy($mask);

您是否尝试过使用imagesavealpha而不是imagesettransparency?将alpha混合设置为false,然后使用imagesavealpha设置为true。最后,您将调用imagecolorallocatealpha函数以获取透明/alpha颜色,而不是imagesettransparency:

imagealphablending($image, false);
imagesavealpha($image, true);

$transparent = imagecolorallocatealpha($image, 255, 255, 255, 127);

imagefilledellipse($mask, $newwidth / 2, $newheight / 2, $newwidth, $newheight, $transparent);
etc...