Php imagettftext: add a shadow for text

Source: Internet
Author: User
Tags int size php tutorial

Array imagettftext (resource image, int size, int angle, int x, int y, int color, string fontfile, string text)


Imagettftext () draws the string text to the image, starting from the coordinates x, y (0, 0 in the upper left corner), angle, color, use the truetype font file specified by fontfile. Depending on the gd library used in the php Tutorial, if fontfile does not start with '/', '. Ttf' will be added to the file name and the library will be searched to define the font path.


*/
// Send the header file
Header ("content-type: image/png ");
// Create an image
$ Im = imagecreatetruecolor (400, 30 );
// Define the color
$ White = imagecolorallocate ($ im, 255,255,255 );
$ Gray = imagecolorallocate ($ im, 128,128,128 );
$ Black = imagecolorallocate ($ im, 0, 0 );
Imagefilledrectangle ($ im, 0, 0,399, 29, $ white );
// Define text
$ Text = 'Hello world! ';
// The path of the font file
$ Font = 'Arial. Ttf ';
// Add a shadow to the text to draw the text in gray.
Imagettftext ($ im, 20, 0, 13, 23, $ gray, $ font, $ text );
// Add text to draw the text in black
Imagettftext ($ im, 20, 0, 10, 20, $ black, $ font, $ text );
// Output png image
Imagepng ($ im );
Imagedestroy ($ im );
/*
This function requires both the gd Library and the freetype library.
*/

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.