I´m trying to make custom sprites based on my own PNGs using PHP, but I got two problems:
- Output Image it´s a collection of stacked PNGs... in other words: source PNGs are one over other.
- I need a transparent background for the output image!
This is the code that I used:
$width = 210;
$height = 190;
$layers = array();
$layers[] = imagecreatefrompng("copy.png");
$layers[] = imagecreatefrompng("cut.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);
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');