2012-10-22 80 views
0

因此,我創建的PHP文件和一些有用的線程/諮詢的腳本上SO以及與此就出來了:陰影正在變成黑色

$filename = time(); 

$glassurl = $_GET['GlassImg']; 
$frameurl = $_GET['FrameImg']; 
$handleurl = "images/helpbutton.png"; 
$handleurl2 = "images/helpbutton.png"; 

$glassimg = imagecreatefromjpeg($glassurl); 
$frameimg = imagecreatefromgif($frameurl); 
$handleimg = imagecreatefrompng($handleurl); 
$handleimg2 = imagecreatefrompng($handleurl2); 

$frame_x = imagesx($frameimg); 
$frame_y = imagesy($frameimg); 
imagecopymerge($glassimg, $frameimg, 0, 0, 0, 0, $frame_x, $frame_y, 100); 

imagecolortransparent($handleimg, imagecolorat($handleimg, 0, 0)); 
imagecolortransparent($handleimg2, imagecolorat($handleimg2, 0, 0)); 

$handle_x = imagesx($handleimg); 
$handle_y = imagesy($handleimg); 
imagecopymerge($glassimg, $handleimg, 460, 150, 0, 0, $handle_x, $handle_y, 100); 


$handle2_x = imagesx($handleimg2); 
$handle2_y = imagesy($handleimg2); 
imagecopymerge($glassimg, $handleimg2, 5, 5, 0, 0, $handle2_x, $handle2_y, 100); 

// Output and free from memory 
imagepng($glassimg, "uploads/$filename.png"); 

imagedestroy($glassimg); 
imagedestroy($frameimg); 
imagedestroy($handleimg); 
imagedestroy($handleimg2); 

它非常作品完美,但有輕微問題。 helpbutton.png,它只是一個佔位符圖像,看到我可以定位圖像併合並它們,最終會產生一個黑色陰影,導致圖像看起來很糟糕。

這是它應該是什麼樣子:

helpbutton.png

這是怎麼弄出來,一旦合併:

helpresult.png

我已經調查了大量的圖像控件,包括混合等,但似乎沒有影響它。有誰知道如何控制陰影不應該在PHP中變暗?

+0

這可能是因爲您上傳這不是一個PNG圖像嘗試上傳PNG圖像 –

+0

其形象是不是PNG圖像?幫助按鈕和最終生成的圖像都是。你的意思是gif和jpeg? – Bohdi

+0

是的確實.... –

回答

0

imagesavealpha($res, true) & imagealphablending($res, false)派上用場,當你用alpha通道保存PNG圖像時(特別是當你從jpeg打開時)。

編輯:試試這個:

$glassimg = imagecreatefromjpeg($glassurl); 
imagealphablending($glassimg, false); 
imagesavealpha($glassimg, true) 

$frameimg = imagecreatefromgif($frameurl); 
imagealphablending($frameimg, false); 
imagesavealpha($frameimg, true) 

$handleimg = imagecreatefrompng($handleurl); 
imagealphablending($handleimg, false); 
imagesavealpha($handleimg, true) 

$handleimg2 = imagecreatefrompng($handleurl2); 
imagealphablending($handleimg2, false); 
imagesavealpha($handleimg2, true) 
+0

我試過這個,並沒有什麼區別......謝謝你:) – Bohdi

+0

你是否應用在每個圖像資源(剛剛打開之後),它們都在'imagecopy' /'imagecopymerge'參數中? – pozs

+0

我不確定你的意思是這個對不起...... – Bohdi