M_PI/2 ) { $yy = 0; for ( $x = 0; $x >= $xStop; $x -= 1 ) { if ( $x > $xStart ) { $y1 = $x/$xStart*$yStart; } else { $y1 = $h * sqrt( 1 - pow( $x,2 ) / pow( $w,2 ) ); } $y2 = $x/$xStop*$yStop; $d1 = $y1 - floor($y1); $d2 = $y2 - floor($y2); $y1 = floor($y1); $y2 = floor($y2); imageLine($img, $cx + $x, $cy - $y1, $cx + $x, $cy - $y2, $fillColor); $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], 100 - $d1*100 ); imageSetPixel($img, $cx + $x, $cy - $y1 - 1, $diffColor); $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], $d2*100 ); imageSetPixel($img, $cx + $x, $cy - $y2 + 1, $diffColor); for ( $yy; $yy <= $y1; $yy += 1 ) { if ( $yy < $yStop ) { $x1 = -$yy/$yStop*$xStop; } else { $x1 = $w * sqrt( 1 - pow( $yy,2 ) / pow( $h,2 ) ); } $d1 = $x1 - floor($x1); $x1 = floor($x1); $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], 100 - $d1*100 ); imageSetPixel($img, $cx - $x1 - 1, $cy - $yy, $diffColor); if ( $start > M_PI/2 ) { $x2 = $yy/$yStart*$xStart; $d2 = $x2 - floor($x2); $x2 = floor($x2); $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], $d2*100 ); imageSetPixel($img, $cx + $x2, $cy - $yy, $diffColor); } } } } $xStart = $w * cos(max(M_PI,$start)); $yStart = $h * sin(max(M_PI,$start)); $xStop = $w * cos($stop); $yStop = $h * sin($stop); if ( $start < 3*M_PI/2 && $stop > M_PI) { $yy = 0; for ( $x = 0; $x >= $xStart; $x -= 1 ) { if ( $x > $xStop) { $y1 = $x/$xStop*$yStop; } else { $y1 = -$h * sqrt( 1 - pow( $x,2 ) / pow( $w,2 ) ); } $y2 = $x/$xStart*$yStart; $d1 = $y1 - floor($y1); $d2 = $y2 - floor($y2); $y1 = floor($y1); $y2 = floor($y2); imageLine($img, $cx + $x, $cy - $y1, $cx + $x, $cy - $y2, $fillColor); $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], $d1*100 ); imageSetPixel($img, $cx + $x, $cy - $y1 + 1, $diffColor); $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], 100 - $d2*100 ); imageSetPixel($img, $cx + $x, $cy - $y2 - 1, $diffColor); for ( $yy; $yy >= $y1; $yy -= 1 ) { if ( $yy > $yStart ) { $x1 = -$yy/$yStart*$xStart; } else { $x1 = $w * sqrt( 1 - pow( $yy,2 ) / pow( $h,2 ) ); } $d1 = $x1 - floor($x1); $x1 = floor($x1); $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], 100 - $d1*100 ); imageSetPixel($img, $cx - $x1 - 1, $cy - $yy, $diffColor); if ($stop < 3*M_PI/2) { $x2 = $yy/$yStop*$xStop; $d2 = $x2 - floor($x2); $x2 = floor($x2); $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], 100 - $d2*100 ); imageSetPixel($img, $cx + $x2 + 1, $cy - $yy, $diffColor); } } } } if ( $start < 2*M_PI && $stop > 3*M_PI/2 ) { $yy = 0; for ( $x = 0; $x <= $xStop; $x += 1 ) { if ( $x < $xStart ) { $y1 = $x/$xStart*$yStart; } else { $y1 = -$h * sqrt( 1 - pow( $x,2 ) / pow( $w,2 ) ); } $y2 = $x/$xStop*$yStop; $d1 = $y1 - floor($y1); $d2 = $y2 - floor($y2); $y1 = floor($y1); $y2 = floor($y2); imageLine($img, $cx + $x, $cy - $y1, $cx + $x, $cy - $y2, $fillColor); $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], $d1*100 ); imageSetPixel($img, $cx + $x, $cy - $y1 + 1, $diffColor); $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], 100 - $d2*100 ); imageSetPixel($img, $cx + $x, $cy - $y2 - 1, $diffColor); for ( $yy; $yy >= $y1; $yy -= 1 ) { if ( $yy > $yStop ) { $x1 = $yy/$yStop*$xStop; } else { $x1 = $w * sqrt( 1 - pow( $yy,2 ) / pow( $h,2 ) ); } $d1 = $x1 - floor($x1); $x1 = floor($x1); $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], 100 - $d1*100 ); imageSetPixel($img, $cx + $x1 + 1, $cy - $yy, $diffColor); if ( $start > 3*M_PI/2 ) { $x2 = $yy/$yStart*$xStart; $d2 = $x2 - floor($x2); $x2 = floor($x2); $diffColor = imageColorExactAlpha( $img, $color[0], $color[1], $color[2], $d2*100 ); imageSetPixel($img, $cx + $x2 , $cy - $yy, $diffColor); } } } } } // Outputs the proper header to the image function outputHeader(){ header( "Content-Type: image/png" ); header( "Expires: ".gmdate( "D, d M Y H:i:s", time() + 24 * 60 *60 ) ); } // Converts a hex color to RGB function hex2rgb( $hex ){ for( $i=0; $i<3; $i++ ){ $temp = substr( $hex, 2*$i, 2 ); $rgb[ $i ] = 16 * hexdec( substr( $temp, 0, 1 ) ) + hexdec( substr( $temp, 1,1 ) ); } return $rgb; } $loc = $_GET['loc'] ? $_GET['loc'] : 'tl'; $style = $_GET['style'] ? $_GET['style'] : 'round'; $width = $_GET['width'] ? $_GET['width'] : 30; $height = $_GET['height'] ? $_GET['height'] : 30; $color = $_GET['color'] ? $_GET['color'] : '000000'; $bgcolor = $_GET['bgcolor'] ? $_GET['bgcolor'] : 'ffffff'; //$borderWidth = $_GET['bwidth'] ? $_GET['bwidth'] : 0; //$borderColor = $_GET['bcolor'] ? $_GET['bcolor'] : 'cccccc'; // Defaults ot prevent errors/notices $borderWidth = (isset($borderWidth)?$borderWidth:0); $borderColor = (isset($borderColor)?$borderColor:'000000'); $caching = true; $cacheDir = 'cache/'; $mangledName = $loc.'_'.$style.'_'.$width.'_'.$height.'_'.$color.'_'.$bgcolor.'_'.$borderWidth.'_'.$borderColor.'.png'; $cacheFile = $cacheDir.$mangledName; //first check to see if we've already generated this file. If so, just return it if( $caching && file_exists( $cacheFile ) ){ outputHeader(); //include( $cacheFile ); print file_get_contents($cacheFile); } else { $rgbColor = hex2rgb( $color ); $rgbBGColor = hex2rgb( $bgcolor ); //$rgbBorder = hex2rgb( $borderColor ); $image = imagecreatetruecolor( $width, $height ); $imageColor = imagecolorallocate( $image, $rgbColor[0], $rgbColor[1], $rgbColor[2] ); $imageBGColor = imagecolorallocate( $image, $rgbBGColor[0], $rgbBGColor[1], $rgbBGColor[2] ); //$imageBorder = imagecolorallocate( $image, $rgbBorder[0], $rgbBorder[1], $rgbBorder[2] ); imagecolortransparent( $image, $imageBGColor ); //$imageBGColor = imagecolorallocate( $image, 255, 0, 0 ); imagefill( $image, 0, 0, $imageBGColor ); if( $loc == "tl" ){ $centerX = $width; $centerY = $height; $arcStart = M_PI / 2; $arcEnd = M_PI; }else if( $loc == "tr" ){ $centerX = -1; $centerY = $height; $arcStart = 0; $arcEnd = M_PI / 2; }else if( $loc == "bl" ){ $centerX = $width; $centerY = -2; $arcStart = M_PI; $arcEnd = 3 * M_PI / 2; }else if( $loc == "br" ){ $centerX = -1; $centerY = -2; $arcStart = 3 * M_PI / 2; $arcEnd = 2 * M_PI; }else if( $loc == "l" ){ $height = ceil( $height / 2 ); $centerX = $width; $centerY = $height - 1; $arcStart = 0; $arcEnd = 2 * M_PI; $width--; $height--; }else if( $loc == "r" ){ $height = ceil( $height / 2 ); $centerX = -1; $centerY = $height - 1; $arcStart = 0; $arcEnd = 2 * M_PI; $width--; $height--; } /*if( $style == 'round' ){ $drawStyle = IMG_ARC_PIE; }else if( $style == 'angle' ){ $drawStyle = IMG_ARC_CHORD; }*/ /*if( $borderWidth != 0 ){ imagefilledarc( $image, $centerX, $centerY, $width * 2, $height * 2, $arcStart, $arcEnd, $imageBorder, $drawStyle ); imagefilledarc( $image, $centerX, $centerY, ( $width - $borderWidth ) * 2, ( $height - $borderWidth ) * 2, $arcStart, $arcEnd, $imageColor, $drawStyle ); }else{*/ //imagefilledarc( $image, $centerX, $centerY, $width * 2, $height * 2, $arcStart, $arcEnd, $imageColor, $drawStyle ); imageSmoothArc( $image, $centerX, $centerY, ($width) * 2, ($height) * 2, $rgbColor, $arcStart, $arcEnd ); //imageSmoothArc( $image, $width/2, $height/2, $width, $height, $rgbColor, 0, 2 * M_PI ); //imageSmoothArc( &$image, 160, 120, 220, 120, $rgbColor, 0, 2 * M_PI ); //imageSmoothArc( &$img, $cx, $cy, $w, $h, $color, $start, $stop); //} outputHeader(); if( $caching ){ ob_start(); imagepng( $image ); $buffer = ob_get_contents(); ob_end_flush(); $fp = fopen( $cacheFile, 'wb' ); fwrite( $fp, $buffer ); fclose( $fp ); } imagepng( $image ); imagedestroy( $image ); } ?>