[center][PHP]Imagecreatefrompng background blijft niet transparant[/center]
Beste leden,
Ik maak een png afbeelding aan vanaf een bestaande png met transparante achtergrond met behulp van php gd library. alles gaat goed maar de achtergrond blijft niet transparant, ze wordt ingekleurd, hoe komt dit? thx
live: demo
Beste leden,
Ik maak een png afbeelding aan vanaf een bestaande png met transparante achtergrond met behulp van php gd library. alles gaat goed maar de achtergrond blijft niet transparant, ze wordt ingekleurd, hoe komt dit? thx
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
| <?php error_reporting(E_ALL + E_STRICT); ini_set( "display_errors", 1); header("Content-type: image/png"); header('Content-Disposition: attachment; filename="button.png"'); class Generate { private $button; public function __construct($font,$size,$image,$color,$text,$align){ $this->constructImage($font,$size,$image,$color,$text,$align); return $this->button; } private function constructImage($font,$size,$image,$color,$text,$align){ $button = imagecreatefrompng($image); $boundingbox = imagettfbbox($size,0,$font,$text); switch ($align) { case "left": $x = 20; break; case "center": $x = (imagesx($button)-($boundingbox[2]))/2; break; case "right": $x = imagesx($button) -($boundingbox[2])-10; break; default: break; } $y = imagesy($button) - (imagesy($button)-$size)/2; $col = imagecolorallocate($button,hexdec($color[1]).hexdec($color[2]),hexdec($color[3]).hexdec($color[4]),hexdec($color[5]).hexdec($color[6])); imagettftext($button,$size,0,$x,$y,$col,$font,$text); readfile($this->button = imagepng($button)); imagedestroy($button); } } ?> |
live: demo
[ Voor 11% gewijzigd door Verwijderd op 16-09-2007 21:23 . Reden: Titel niet ok ]