This article mainly introduces php Technology to load fonts and save them as images. For more information, see
This article mainly introduces php Technology to load fonts and save them as images. For more information, see
The following code explains how to use php to load fonts and save them as images. // 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 = done', "a"); fwrite ($ fp2, $ img); fclose ($ fp2 );
The above code can load the font and save it as an image.