I'm trying to create some text in an image using Imagettftext() functions. I found some code from 999 tutorials here, and got it to work work some modifications :
Code: Select all
$theText = "999 Tutorials, transparent text";
$fontSize = 18;
$angle = 0;
$font = "./fonts/Ariendesse.ttf";
header("Content-type: image/png");
$size = imageTTFBBox($fontSize, $angle, $font, $theText);
$height = abs($size[5] - $size[3]);
$width = abs($size[2] - $size[0]);
$image = imageCreateTrueColor($width,$height);
imageSaveAlpha($image, true);
ImageAlphaBlending($image, false);
$transparentColor = imagecolorallocatealpha($image, 200, 200, 200, 127);
Imagefill($image, 0, 0, $transparentColor);
//$background_color = imagecolorallocatealpha($image, 0,0,0,12);
$textColor = imagecolorallocate($image, 200, 0, 0);
$result = imagettftext($image, $fontSize, 0, 0, $height, $textColor, $font, $theText); //** Problem here
imagepng($image);
imagepng($image, "textImage.png");
imagedestroy($image);