Developer Snippet Diary

GD library |Add your own fount for text using imagettftext ||PHP

$image=imagecreatetruecolor(500, 600);
imagefilledrectangle($image, 0, 0, 500, 600,0x02B0B4);//set background color
imagefilledrectangle($image, 10, 10, 200, 200,0x0222B4);//set background color
imagesetthickness( $image, 10 );
$imageWidth=imagesx($image);
$imageHeight=imagesy($image);
$text="Rizwan Akhtar Gondal";
$textLength=strlen($text);
$fontSize= intval($imageWidth/$textLength);	
//array imagettftext( resource $image, float $size, float $angle,int $x, int $y, int $color, string $fontfile, string $text); //add ttf font for text on image
$text=imagettftext($image,$fontSize, 0, 0, $fontSize+10,0xFFFFFF, realpath('Sophia.ttf'),$text);
header('Content-type: image/png');
imagepng($image);
imagedestroy($image);
Posted by: R GONDAL
Email: rizikmw@gmail.com