I have this code:
header("Content-type: image/png");
$string = "My text";
$font = 2;
$width = imagefontwidth($font) * strlen($string);
$height = imagefontheight($font);
$image = imagecreatetruecolor ($width,$height);
$white = imagecolorallocate ($image,255,255,255);
$black = imagecolorallocate ($image,0,0,0);
imagefill($image,0,0,$white);
imagestring ($image,$font,0,0,$string,$black);
imagepng ($image);
imagedestroy($image);
How can I simply make sure the background is transparent?
Avram
2
Try something like this:
header("Content-type: image/png");
$string = "My text";
$font = 2;
$width = imagefontwidth($font) * strlen($string);
$height = imagefontheight($font);
$image = imagecreatetruecolor ($width,$height);
imagealphablending($image , false);
imagesavealpha($image , true);
$transparent = imagecolorallocatealpha($image , 255, 255, 255, 127);
$white = imagecolorallocate ($image,255,255,255);
$black = imagecolorallocate ($image,0,0,0);
imagefill($image,0,0,$transparent);
imagestring ($image,$font,0,0,$string,$black);
imagepng ($image);
imagedestroy($image);