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);
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

Related Article

Alibaba Cloud 10 Year Anniversary

With You, We are Shaping a Digital World, 2009-2019

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.