PHP imagecopymerge源图像的背景更改透明为黑色

我需要合并两张图片,

代码是这样的:</ p>

  $ image = imagecreatefromjpeg(“images / big.jpg”);

$ image1 = imagecreatefrompng(“small_image / 8.png”);
$ size = getimagesize(“small_image / 8.png”);

imagecopymerge($ image,$ image1,400,30,0 ,0,$ size [0],$ size [1],100);
header('Content-Type:image / gif');
imagegif($ image);
imagedestroy($ image1);
</ 代码> </ pre>



frist图片是:</ p>

</ p>

第二个是:
“在此输入图像描述” </ p>

最终结果不透明</ p>

</ p>

请帮助!!!谢谢!</ p>

新版代码:< / p>

  $ image = imagecreatefromjpeg(“images / big.jpg”);

$ image1 = imagecreatefrompng(“small_image / 8.png”);
$ size = getimagesize(“small_image / 8.png”);
$ background = imagecolorallocate($ image,0,0,0); \ nimagecolortransparent($ image,$ background);
imagealphablending($ image1,false);
imagesavealpha($ image1,true);

imagecopymerge($ image,$ image1,400,30,0,0,$ size [0],$ size [1],100);

header('Content-Type:image / gif');

imagegif($ image);
imagedestroy($ image1);
< / code> </ pre>

,结果是:
</ p>
</ div>

展开原文

原文

I need to merge two pictures, my code is like this:

$image = imagecreatefromjpeg("images/big.jpg"); 
$image1 = imagecreatefrompng("small_image/8.png");
$size = getimagesize("small_image/8.png");


imagecopymerge($image, $image1, 400, 30, 0, 0, $size[0], $size[1], 100);
header('Content-Type: image/gif');
imagegif($image);
imagedestroy($image1);


the frist picture is :

enter image description here

second is : enter image description here

final result not transparent

enter image description here

Please help!!!Thanks!

new version of code:

$image = imagecreatefromjpeg("images/big.jpg"); 
$image1 = imagecreatefrompng("small_image/8.png");
$size = getimagesize("small_image/8.png");
$background = imagecolorallocate($image, 0, 0, 0);
imagecolortransparent($image, $background);
imagealphablending($image1, false);
imagesavealpha($image1, true);


imagecopymerge($image, $image1, 400, 30, 0, 0, $size[0], $size[1], 100);

header('Content-Type: image/gif');


imagegif($image);
imagedestroy($image1);

and the result is : enter image description here

php
dougui4325
dougui4325 我编辑了我的问题和结果,你可以看看..
7 年多之前 回复
dongtang1966
dongtang1966 您已在“相关”列中的第一个问题中尝试过解决方案但它们无法正常工作?然后,您应该相应地更新您的代码以反映这一点。
7 年多之前 回复
dongshang1768
dongshang1768 我,我试过......但找不到完美的解决方案..
7 年多之前 回复
dtnmuyoiw680512744
dtnmuyoiw680512744 您是否检查了在撰写问题标题时向您建议的重复项(它们位于右侧的“相关”列中)?
7 年多之前 回复

1个回答



Ok..i现在找到了一个解决方案.. </ p>

  $ image = imagecreatefromjpeg  ( “图像/ show01.jpg”);  // 
$ image1 = imagecreatefrompng(“small_image / 1.png”); //
$ image3 = imagecreatefromgif(“images / carBg.gif”); //
$ size = getimagesize(“small_image / 1。 png“);
$ overlay = imagecreatetruecolor(80,80);

$ white = imagecolorallocate($ overlay,229,229,229);
imagefilledrectangle($ overlay,0,0,80,80,$ 白);

imagecolortransparent($覆盖,$白色);

imagecopy($ overlay,$ image1,(80- $ size [0])/ 2,(80- $ size [1])/ 2,0,0,$ size [0],$ size [1]) ;
imagecopymerge($ image3,$ overlay,0,0,0,00,80,100);

imagecopymerge($ image,$ image3,280,30,0,0,80,80, 100);

header('Content-Type:image / png');

//最后输出结果
imagepng($ image);
imagedestroy($ image);
</ code > </ pre>
</ div>

展开原文

原文

Ok..i found a solution now..

$image = imagecreatefromjpeg("images/show01.jpg"); //
$image1 = imagecreatefrompng("small_image/1.png");//
$image3 = imagecreatefromgif("images/carBg.gif");//
$size = getimagesize("small_image/1.png");
$overlay = imagecreatetruecolor(80, 80);

$white = imagecolorallocate($overlay, 229, 229, 229);
imagefilledrectangle($overlay, 0, 0, 80, 80, $white);

imagecolortransparent($overlay,$white);  
     imagecopy($overlay, $image1, (80-$size[0])/2, (80-$size[1])/2, 0, 0,   $size[0],$size[1]);
imagecopymerge($image3, $overlay, 0, 0, 0, 0, 80, 80, 100);


imagecopymerge($image, $image3, 280, 30, 0, 0, 80, 80, 100);

header('Content-Type: image/png');

// and finally, output the result
imagepng($image);
imagedestroy($image);

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问