note 57696 added to function.imagefilledellipse

From: Date: Tue, 11 Oct 2005 17:12:22 +0000
Subject: note 57696 added to function.imagefilledellipse
Groups: php.notes 
Request: Send a blank email to php-notes+get-96838@lists.php.net to get a copy of this message
Here is a simple script using imagefilledellipse to created rounded corners on the fly. It takes color, bg_color, width, height, and placement (i.e. top left, bottom right) as arguments. <?php $color = $_REQUEST['color']; $bg_color = $_REQUEST['bg_color']; $c_width = $_REQUEST['width']; $c_height = $_REQUEST['height']; $placement = $_REQUEST['placement']; $width = 2 * $c_width; $height = 2 * $c_height; // create a blank image $image = imagecreatetruecolor($c_width, $c_height); // fill the corner color $col_ellipse = hex2int($image, $color); // fill the background color $bg = hex2int($image, $bg_color); // fill the background color imagefill($image, 0, 0, $bg); // draw the ellipse //takes (resource image, int cx, int cy, int w, int h, int color) // bottom right corner if ($placement == "br") {imagefilledellipse($image, 0, 0, $width, $height, $col_ellipse);} // top right corner if ($placement == "tl") {imagefilledellipse($image, $c_width, $c_height, $width, $height, $col_ellipse);} // top left corner if ($placement == "tr") {imagefilledellipse($image, 0, $c_height, $width, $height, $col_ellipse);} // bottom left corner if ($placement == "bl") {imagefilledellipse($image, $c_width, 0, $width, $height, $col_ellipse);} // output the picture header("Content-type: image/png"); imagepng($image); function hex2int($image, $color) { $string = str_replace("#","",$color); $red = hexdec(substr($string,0,2)); $green = hexdec(substr($string,2,2)); $blue = hexdec(substr($string,4,2)); $color_int = imagecolorallocate($image, $red, $green, $blue); return($color_int); } ?> You would call it like so: <img src="round_test.php? width=50&height=50&color=fffefe&bg_color=99e1e0&placement=tr"> ---- Manual Page -- http://www.php.net/manual/en/function.imagefilledellipse.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57696 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57696&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57696&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57696&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57696&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57696&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57696&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57696&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57696&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#96838) next »