Use PHP to draw a button that can change text

Source: Internet
Author: User
Tags abs html tags
You always spend a lot of time to do some push button, to design a good button background all use it!
The text can be changed freely!

?
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 Long 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,b
$blue = Imagecolorallocate ($im, 0X2C,0X6D,0XAF);
$black = Imagecolorallocate ($im, 0,0,0);
$white = Imagecolorallocate ($im, 255,255,255);
Drawing
Imagerectangle ($im, 0,0, $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 can't add any HTML tags to this code, especially if you don't allow it. Join with?>!

Write the following code when invoked:

S is the size of the picture, text is the text of the picture
Try it quickly!

Author: Rasmus Lerdorf


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.