This article mainly introduces php Technology to load fonts and save them as images. For more information about php technology, see the following code.
// Set the content-type header ("Content-type: image/png"); // Create the image $ im = imagecreatetruecolor (400,100 ); // Create some colors $ white = imagecolorallocate ($ im, 255,255,255); $ gray = imagecolorallocate ($ im, 128,128,128); $ black = imagecolorallocate ($ im, 0, 0, 0); imagefilledrectangle ($ im, 0, 0,399,100, $ white); // The text to draw $ text = 'Dictionary net '; // Replace path by your own font path $ font = 'fontname. ttf'; // Add some shadow to the text // imagettftext ($ im, 60, 0, 11, 21, $ gray, $ font, $ text ); // Add the text imagettftext ($ im, 60, 0, 0, 70, $ black, $ font, $ text); // Using imagepng () results in clearer text compared with imagejpeg () imagepng ($ im); imagedestroy ($ im );
To save the graph, use the following code:
ob_start(); imagejpeg($im); $img = ob_get_contents(); ob_end_clean(); $size = strlen($img); $fp2=@fopen('tst.jpg', "a"); fwrite($fp2,$img); fclose($fp2);
The above code can load the font and save it as an image.