2008-09-15 30 views
1

文字が正しい方向を向くように画像を反転する必要があります。これは、彼らが言うように以下画像を水平方向に反転

(背景が白になる)。私が午前

問題がGIF画像で、私は透明性を失うように見えるということです。「オンザフライ」で行われる必要があるコードです:。。(代わりに誰かが良い例に私を送ることができる)

$img = imagecreatefromgif("./unit.gif"); 

$size_x = imagesx($img); 
$size_y = imagesy($img); 

$temp = imagecreatetruecolor($size_x, $size_y); 

imagecolortransparent($img, imagecolorallocate($img, 0, 0, 0)); 
imagealphablending($img, false); 
imagesavealpha($img, true); 

$x = imagecopyresampled($temp, $img, 0, 0, ($size_x-1), 0, $size_x, $size_y, 0-$size_x, $size_y); 

if ($x) { 
    $img = $temp; 
} 
else { 
    die("Unable to flip image"); 
} 

header("Content-type: image/gif"); 
imagegif($img); 
imagedestroy($img); 

答えて

2

することはすべきではない、この:

imagecolortransparent($img, imagecolorallocate($img, 0, 0, 0)); 
imagealphablending($img, false); 
imagesavealpha($img, true); 

...このこと:

imagecolortransparent($temp, imagecolorallocate($img, 0, 0, 0)); 
imagealphablending($temp, false); 
imagesavealpha($temp, true); 

は、ソース画像、作成した$の一時画像のためにこれらの関数を呼び出していないする必要があります。

1

あなたがImageMagickのの存在を保証することができる場合、あなたは彼らのmogrify -flopコマンドを使用することができますこれは、透明性を維持し

2

最終結果:

$size_x = imagesx($img); 
$size_y = imagesy($img); 

$temp = imagecreatetruecolor($size_x, $size_y); 

imagecolortransparent($temp, imagecolorallocate($temp, 0, 0, 0)); 
imagealphablending($temp, false); 
imagesavealpha($temp, true); 
$x = imagecopyresampled($temp, $img, 0, 0, ($size_x-1), 0, $size_x, $size_y, 0-$size_x, $size_y); 
if ($x) { 
    $img = $temp; 
} 
else { 
    die("Unable to flip image"); 
} 

header("Content-type: image/gif"); 
imagegif($img); 
imagedestroy($img); 
+0

更新されたコードを掲示するための感謝。それは私に役立つ – JakeParis

関連する問題