Beste leden,
Ik creeƫr een plaatje met de gd library van php vanaf een bestaande png met transparante achtergrond, na het generen heeft het plaatje geen transparante achtergron meer maar een gekleurde achtergrond, hoe komt dit?
<?php
error_reporting(E_ALL + E_STRICT);
ini_set( "display_errors", 1);
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);
header("Content-type: image/png");
header('Content-Disposition: attachment; filename="button.png"');
readfile($this->button = imagepng($button));
imagedestroy($button);
}
}
?>
EDIT: Live Demo
2.870 views