PHP meerdere images naar één: niet zwart-wit!
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.)
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.)
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?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);
?>
$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);
?>
Gewijzigd op 17/07/2013 19:13:49 door Tom aan t Goor
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.
En afbeeldingen met een overloop van transparant naar wit/geel wordt nu zwart.
Code (php)
1
2
3
4
5
6
2
3
4
5
6
<?php
$dest = imagecreatetruecolor(300, 300);
imagealphablending($dest, true);
$black = imagecolorallocate($dest, 0,0,0);
imagecolortransparent($dest, $black);
?>
$dest = imagecreatetruecolor(300, 300);
imagealphablending($dest, true);
$black = imagecolorallocate($dest, 0,0,0);
imagecolortransparent($dest, $black);
?>
Gewijzigd op 17/07/2013 22:20:57 door Tom aan t Goor