Use PHP to draw a button that can replace text

Source: Internet
Author: User
Tags abs

You always have to spend a lot of time making some buttons. Design a good button and use it all!
Text can be changed at will!

<?
Header ("Content-type: image/gif ");
If (! Isset ($ s) $ s = 11;
// Times. tif can be any font you like
$ Size = imagettfbbox ($ s, 0, "/fonts/TIMES. TTF", $ text );
// Set the length and width
$ Dx = abs ($ size [2]-$ size [0]);
$ Dy = abs ($ size [5]-$ size [3]);
$ Xpad = 9;
$ Ypad = 9;
$ Im = imagecreate ($ dx $ xpad, $ dy $ ypad );
// Set R, G, and B
$ Blue = ImageColorAllocate ($ im, 0x2c, 0x6D, 0xAF );
$ Black = ImageColorAllocate ($ im, 0, 0 );
$ White = ImageColorAllocate ($ im, 255,255,255 );
// Draw
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 );
?>

The important thing is that you cannot add any HTML tag to this code, especially when you do not agree to <? And?> Join!

Write the following code during the call:

S is the image size. text is the image text.
Try it!

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.