note 47027 added to function.imagettftext
| From: | RickardDahlstand at osu1 dot php dot net | Date: | Sun, 31 Oct 2004 10:59:58 +0000 |
| Subject: | note 47027 added to function.imagettftext | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-79387@lists.php.net to get a copy of this message | ||
Here is a generic button or menu generator script using this function. It handles automatic shading
of the button, automatic size based on the length of the text and a nice looking arrow for
form-buttons. The font can be downloaded from http://www.pfonts.com/s/sevenet7.ttf (and this one
has Swedish characters!!)
Have fun!
<?php
header ("Content-type: image/png");
// Fontsize
$size = 8;
// Buttonsize
$buttonsize = 17;
// Font
$type = "ttf/sevenet7.ttf";
// Get the text
$text = $HTTP_GET_VARS['text'];
// If true show an arrow.
$arrow = ($HTTP_GET_VARS['arrow']=="true");
// If true make the image a bit ligher.
$over = ($HTTP_GET_VARS['over']=="true");
// Default color.
$red = 99;
$green = 111;
$blue = 164;
// Make a red button.
if ($HTTP_GET_VARS['color']=="red") {
$red = 211;
$green = 77;
$blue = 77;
};
// Make a green button.
if ($HTTP_GET_VARS['color']=="green") {
$red = 81;
$green = 211;
$blue = 90;
};
if ($arrow) { $extrax = 12; $extray = 1; } else { $extrax = 0; $extray = 0; };
$bbox = imagettfbbox($size, 0, $type, $text);
$maxx = $bbox[2]+22+$extrax;
$maxy = $buttonsize+$extray;
$im = imagecreate ($maxx, $maxy);
if ($over) {
$red += 35;
$green += 35;
$blue += 35;
};
$back = imagecolorallocate ($im, $red, $green, $blue);
$color1 = imagecolorallocate ($im, $red+40, $green+40, $blue+40);
$color2 = imagecolorallocate ($im, $red+23, $green+23, $blue+23);
$color3 = imagecolorallocate ($im, $red-10, $green-10, $blue-10);
$color4 = imagecolorallocate ($im, $red-30, $green-30, $blue-30);
$white = imagecolorallocate ($im, 255, 255, 255);
$black = imagecolorallocate ($im, 0, 0, 0);
imageline ($im, 0, 0, $maxx, 0, $black);
imageline ($im, 0, 1, $maxx, 1, $color1);
imageline ($im, 0, 2, $maxx, 2, $color2);
imageline ($im, 0, $maxy-3, $maxx, $maxy-3, $color3);
imageline ($im, 0, $maxy-2, $maxx, $maxy-2, $color4);
imageline ($im, 0, $maxy-1, $maxx, $maxy-1, $black);
imageline ($im, 0, $maxy-1, $maxx, $maxy-1, $black);
imageline ($im, 0, 0, 0, $maxy, $black);
imageline ($im, $maxx-2, 0, $maxx-2, $maxy, $black);
imageline ($im, $maxx-1, 0, $maxx-1, $maxy, $white);
imageline ($im, $maxx-1, 0, $maxx-1, $maxy, $white);
if ($arrow) {
$sx = 6;
$sy = (ceil($maxy/2))-5;
imageline ($im, 0+$sx, 4+$sy, 9+$sx, 4+$sy, $white);
imageline ($im, 0+$sx, 5+$sy, 9+$sx, 5+$sy, $white);
imageline ($im, 5+$sx, 0+$sy, 9+$sx, 4+$sy, $white);
imageline ($im, 5+$sx, 1+$sy, 8+$sx, 4+$sy, $white);
imageline ($im, 4+$sx, 1+$sy, 7+$sx, 4+$sy, $white);
imageline ($im, 5+$sx, 9+$sy, 9+$sx, 5+$sy, $white);
imageline ($im, 5+$sx, 8+$sy, 8+$sx, 5+$sy, $white);
imageline ($im, 4+$sx, 8+$sy, 7+$sx, 5+$sy, $white);
}
imagettftext ($im, $size, 0, 9+$extrax, 2+(floor($maxy/2)), -$white, $type, $text);
imagepng ($im);
imagedestroy ($im);
?>
----
Manual Page -- http://www.php.net/manual/en/function.imagettftext.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47027
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47027&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47027&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47027&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47027&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47027&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47027&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47027&report=yes
Search -- http://master.php.net/manage/user-notes.php