Php loads the font and saves it as an image

Source: Internet
Author: User
Tags imagejpeg
Php loads the font and saves it as an image [Php]View plain copy

  1. // Set the content-type
  2. Header ("Content-type: image/png ");
  3. // Create the image
  4. $ Im = imagecreatetruecolor (400,100 );
  5. // Create some colors
  6. $ White = imagecolorallocate ($ im, 255,255,255 );
  7. $ Gray = imagecolorallocate ($ im, 128,128,128 );
  8. $ Black = imagecolorallocate ($ im, 0, 0, 0 );
  9. Imagefilledrectangle ($ im, 0, 0,399,100, $ white );
  10. // The text to draw
  11. $ Text = 'Dictionary net ';
  12. // Replace path by your own font path
  13. $ Font = 'fontname. ttf ';
  14. // Add some shadow to the text
  15. // Imagettftext ($ im, 60, 0, 11, 21, $ gray, $ font, $ text );
  16. // Add the text
  17. Imagettftext ($ im, 60, 0, 0, 70, $ black, $ font, $ text );
  18. // Using imagepng () results in clearer text compared with imagejpeg ()
  19. Imagepng ($ im );
  20. Imagedestroy ($ im );

To save the graph, use the following code:

[Html]View plain copy

    1. Ob_start ();
    2. Imagejpeg ($ im );
    3. $ Img = ob_get_contents ();
    4. Ob_end_clean ();
    5. $ Size = strlen ($ img );
    6. Export fp2=@fopen('tst.jpg ', "");
    7. Fwrite ($ fp2, $ img );
    8. Fclose ($ fp2 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.