0

友達複数の透過PNG画像から1つのpng画像を生成したいのですが、最後の画像しか生成できないのが問題です

両方の画像を結合することはできません。

私のコードは以下のとおりです

$x = 363;
$y = 267;

$im_dest = imagecreatetruecolor ($x, $y);
imagealphablending($im_dest, false);

$im = imagecreatefrompng('2.png');
$im1 = imagecreatefrompng('1.png');

imagecopy($im_dest, $im1, 0, 0, 0, 0, $x, $y);
imagecopy($im_dest, $im, 0, 0, 0, 0, $x, $y);

imagesavealpha($im_dest, true);
imagepng($im_dest, 'small_redfade.png');

これらは、単一の画像に参加するために使用している画像です

http://s11.postimg.org/h6lui7yjn/image.png

http://s21.postimg.org/o7zdnwcnb/image.png

4

2 に答える 2

2

動作するコードは次のとおりです。

$width = 210;
$height = 190;

$layers = array();
$layers[] = imagecreatefrompng("img/01_boy_faceB.png");
$layers[] = imagecreatefrompng("img/01_boy_hairB.png");

$image = imagecreatetruecolor($width, $height);

// to make background transparent
imagealphablending($image, false);
$transparency = imagecolorallocatealpha($image, 0, 0, 0, 127);
imagefill($image, 0, 0, $transparency);
imagesavealpha($image, true);

/* if you want to set background color
$white = imagecolorallocate($image, 255, 255, 255);
imagefill($image, 0, 0, $white);
*/

imagealphablending($image, true);
for ($i = 0; $i < count($layers); $i++) {
    imagecopy($image, $layers[$i], 0, 0, 0, 0, $width, $height);
}
imagealphablending($image, false);
imagesavealpha($image, true);

imagepng($image, 'final_img.png');

?>
于 2014-04-03T17:42:30.730 に答える