Php loads the font and saves it as an image
[Php]View plain copy
-
- // 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:
[Html]View plain copy
- Ob_start ();
- Imagejpeg ($ im );
- $ Img = ob_get_contents ();
- Ob_end_clean ();
- $ Size = strlen ($ img );
-
- Export fp2=@fopen('tst.jpg ', "");
- Fwrite ($ fp2, $ img );
- Fclose ($ fp2 );