PHP Technology for loading fonts and saving images _php instances

Source: Internet
Author: User
Tags imagejpeg
Below through a piece of code for you to introduce the next PHP technology to implement loading fonts and save as a picture.
Set the Content-type header ("Content-type:image/png");  Create the image $im = Imagecreatetruecolor (+);  Create some colors $white = imagecolorallocate ($im, 255, 255, 255); $grey = Imagecolorallocate ($im, 128, 128, 128); $black = imagecolorallocate ($im, 0, 0, 0); Imagefilledrectangle ($im, 0, 0, 399, N, $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, 0, one, one, $grey, $font, $text);  Add the text imagettftext ($im, 0, 0, $black, $font, $text);  Using imagepng () results in clearer text compared with imagejpeg () imagepng ($im); Imagedestroy ($im);  


If you want to save the diagram, use the following code

Ob_start ();    Imagejpeg ($im); $img = Ob_get_contents ();  Ob_end_clean ();  $size = strlen ($img);    $fp 2= @fopen (' tst.jpg ', ' a ');  Fwrite ($fp 2, $img);  Fclose ($fp 2);  

The above code can be finished loading fonts and save as a picture, I hope you will like

  • Related Article

    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.