2012-04-19 8 views
0

完全に透明な背景が必要なPHP GDで画像を作成するコードを使用しています。私はそれを作成すると、それはブラウザでうまく表示されますが、私のiPhoneアプリでは悪いです。私は理由を知らないが、私のiPhoneではすべての透過性が黒で表示されている。これはGDの問題のようです.GDイメージをWebエディタに読み込んで再エクスポートすると、iPhoneアプリでうまく表示されるためです。 GDや何かからpngイメージをエクスポートする特別な方法はありますか、これは何らかのバグですか?ここでは、コードは次のようになります。iPhoneでPHP GD透明度が機能しない

$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); 

答えて

0

は、あなたの代わりにimagesettransparencyのimagesavealphaを使用してみましたか?アルファブレンディングをfalseに設定してから、imagesavealphaをtrueに設定します。最後にimagecolorallocatealpha関数を呼び出して、画像セットの透明度の代わりに透明/アルファ色を取得します:

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

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

imagefilledellipse($mask, $newwidth/2, $newheight/2, $newwidth, $newheight, $transparent); 
etc... 
関連する問題