note 34808 added to function.imagettftext

From: Date: Thu, 07 Aug 2003 08:20:58 +0000
Subject: note 34808 added to function.imagettftext
Groups: php.notes 
Request: Send a blank email to php-notes+get-53557@lists.php.net to get a copy of this message
A nice method to draw a button with curved edges ! <? function get_settings() { global $background, $foreground, $text, $size, $font; $background = $_REQUEST['background']; $foreground = $_REQUEST['foreground']; $text = $_REQUEST['text']; $size = $_REQUEST['size']; $font = $_REQUEST['font']; } function get_color( $str ) { list($r, $g, $b) = explode(',', $str); $arr["red"] = $r; $arr["green"] = $g; $arr["blue"] = $b; return $arr ; } get_settings(); if (! isset($font) ) $font = "verdana"; if (! isset($text) ) $text = "back to list"; if (! isset($size) ) $size = 10; if (! isset($foreground) ) $foreground = "255,255,255"; if (! isset($background) ) $background = "100,100,100"; $fontbox = imagettfbbox($size, 0, $font, $text); $dx = abs($fontbox[2] - $fontbox[0]); $dy = abs($fontbox[5] - $fontbox[3]); $xpad = 16; $ypad = 16; $im_width = $dx + $xpad; $im_height = $dy + $ypad; $im = imagecreate($im_width, $im_height); $color_arr = get_color( $background ); $bacolor = ImageColorAllocate($im, $color_arr["red"], $color_arr["green"], $color_arr["blue"]); unset($color_arr); $color_arr = get_color( $foreground ); $focolor = ImageColorAllocate($im, $color_arr["red"], $color_arr["green"], $color_arr["blue"]); $white = ImageColorAllocate($im, 255, 255, 255); $black = ImageColorAllocate($im, 0, 0, 0); $trans = ImageColorAllocateAlpha($im, 0, 0, 0, 127); ## writing text and frame ## ImageRectangle($im, 0, 0, $dx + $xpad - 1, $dy + $ypad - 1, $black); ImageRectangle($im, 0, 0, $dx + $xpad, $dy + $ypad, $white); ImageTTFText($im, $size, 0, (int)($xpad / 2) + 1, $dy + (int)($ypad / 2), $black, $font, $text); ImageTTFText($im, $size, 0, (int)($xpad / 2), $dy + (int)($ypad / 2) - 1, $focolor, $font, $text); ### drawing curved corners (top left, top right, bottom left, bottom right)## ImageFilledRectangle( $im, 0, 0, (int)$xpad / 2, (int)$ypad / 2, $trans); ImageFilledRectangle( $im, $im_width - (int)$xpad / 2, 0, $im_width, (int)$ypad / 2, $trans); ImageFilledRectangle( $im, 0, $im_height - (int)$ypad / 2, (int)$xpad / 2, $im_height, $trans); ImageFilledRectangle( $im, $im_width - $xpad / 2, $im_height - (int)$ypad / 2, $im_width, $im_height, $trans); ImageFilledArc($im, (int)$xpad / 2, (int)$ypad / 2, (int)$xpad, (int)$ypad, 180, 270, $bacolor, 0); ImageFilledArc($im, $im_width - (int)$xpad / 2, (int)$ypad / 2, (int)$xpad, (int)$ypad, 270, 360, $bacolor, 0); ImageFilledArc($im, (int)$xpad / 2, $im_height - (int)$ypad / 2, (int)$xpad, (int)$ypad, 90, 180, $bacolor, 0); ImageFilledArc($im, $im_width - (int)$xpad / 2, $im_height - (int)$ypad / 2, (int)$xpad, (int)$ypad, 0, 90, $bacolor, 0); ImageFilledArc($im, $im_width - (int)$xpad / 2, $im_height - (int)$ypad / 2, (int)$xpad, (int)$ypad, 0, 90, $black, IMG_ARC_NOFILL); Imagepng($im,'temp.png'); ImageDestroy($im); ?> <html> <body> <img src="temp.png"> </body> </html> ---- Manual Page -- http://www.php.net/manual/en/function.imagettftext.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+34808 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+34808&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+34808&report=yes

« previous php.notes (#53557) next »