Use PHP to generate a dynamic image [from Osso]

Source: Internet
Author: User
Tags abs html tags
Many people do not know that PHP can generate non-HTML data. This is very useful for generating image graphs. It can generate a simple ad horizontal chart from the database or simply generate only one graphic button.
I use TTF in the following example
I usually name it 'Button. php3 ':
######################################## ###############
----- Button. php3 ------
<?
Header ("Content-type: image/gif ");
If (! Isset ($ s) $ s = 11;
$ Size = imagettfbbox ($ s, 0, "fonts/TIMES. TTF", $ text );
$ Dx = abs ($ size [2]-$ size [0]);
$ Dy = abs ($ size [5]-$ size [3]);
$ Xpad = 9;
$ Ypad = 9;
$ Im = imagecreate ($ dx + $ xpad, $ dy + $ ypad );
$ Blue = ImageColorAllocate ($ im, 0x2c, 0x6D, 0xAF );
$ Black = ImageColorAllocate ($ im, 0, 0 );
$ White = ImageColorAllocate ($ im, 255,255,255 );
ImageRectangle ($ im, $ dx + $ xpad-1, $ dy + $ ypad-1, $ black );
ImageRectangle ($ im, 0, 0, $ dx + $ xpad, $ dy + $ ypad, $ white );
ImageTTFText ($ im, $ s, 0, (int) ($ xpad/2) + 1, $ dy + (int) ($ ypad/2), $ black, "fonts/TIMES. TTF ", $ text );
ImageTTFText ($ im, $ s, 0, (int) ($ xpad/2), $ dy + (int) ($ ypad/2)-1, $ white, "fonts/TIMES. TTF ", $ text );
ImageGif ($ im );
ImageDestroy ($ im );
?>
######################################## ###############
It is very important that you cannot put any HTML tags in this file. There cannot be blank lines in the file <? And?> Before or after the tag. If you see an incomplete image after using this Script, it means that you may mistakenly typed characters outside the PHP tag.
The above script can be called in the webpage by syntax:
######################################## ###############

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.