Hoi,

Ik heb een stuk code gemaakt, om meerdere .png bestanden naar 1 .png bestand te maken.
Dit doe ik door ze onder elkaar te zetten.

Alleen nu heb ik het probleem dat alles in zwart-wit is, en dit begrijp ik niet.
Kan iemand me dit uitleggen?
(Ook is de background transparant.)

<?php
$location = 'images/';
$images = array('dots.png', 'footer.png');

for($i=0;$i<count($images);$i++){
$src[$i] = imagecreatefrompng($location.$images[$i]);
list($src[$i.'-w'], $src[$i.'-h'], $src[$i.'-t'], $src[$i.'-a']) = getimagesize($location.$images[$i]); // width - height - type - attribute
$totalheight += $src[$i.'-h'];
if($src[$i.'-w'] > $totalwidth){
$totalwidth = $src[$i.'-w'];
}
}

$dest = imagecreate(300, 300);

for($i=0;$i<count($images);$i++){
imagecopy($dest, $src[$i], 0, $nowheight, 0, 0, $src[$i.'-w'], $src[$i.'-h']);
$nowheight += $src[$i.'-h'];
}

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

imagedestroy($dest);
?>
Ik heb nu dit staan, alleen afbeeldingen met een witte achtergrond wordt nu ook transparant, en dat is niet de bedoeling.
En afbeeldingen met een overloop van transparant naar wit/geel wordt nu zwart.
<?php
$dest = imagecreatetruecolor(300, 300);
imagealphablending($dest, true);
$black = imagecolorallocate($dest, 0,0,0);
imagecolortransparent($dest, $black);
?>

Reageren