2012-10-22 79 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