//Originally written by Wendell Brow and found at http://www.arkie.net/~scripts/thermometer/ // Modified by David Sovinski www.aslandata.com 12/07/2005 to allow for goal being reached or exceeded <?php function thermGraph( $current, $goal, $width, $height, $font ) { $bar = 0.50; // create the image $image = ImageCreate($width, $height); $bg = ImageColorAllocate($image,255,255,255 ); // white $fg = ImageColorAllocate($image,255,0,0); // red $tx = ImageColorAllocate($image,0,0,0); // black // Build background ImageFilledRectangle($image,0,0,$width,$height,$bg); // Build bottom bulb imagearc($image, $width/2, $height-($width/2), $width, $width, 0, 360, $fg); ImageFillToBorder($image, $width/2, $height-($width/2), $fg, $fg); // Build "Bottom level ImageFilledRectangle($image, ($width/2)-(($width/2)*$bar), $height-$width, ($width/2)+(($width/2)*$bar), $height-($width/2), $fg ); // Draw Top Border ImageRectangle( $image, ($width/2)-(($width/2)*$bar), 0, ($width/2)+(($width/2)*$bar), $height-$width, $fg); // Fill to % ImageFilledRectangle( $image, ($width/2)-(($width/2)*$bar), ($height-$width) * (1-($current/$goal)), ($width/2)+(($width/2)*$bar), $height-$width, $fg ); // Add tic's for( $k=5; $k<100; $k+=5 ) { ImageFilledRectangle( $image, ($width/2)+(($width/2)*$bar) -5, ($height-$width) - ($height-$width)*($k/100) -1, ($width/2)+(($width/2)*$bar) -1, ($height-$width) - ($height-$width)*($k/100) +1, $tx ); ImageString($image, $font, ($width/2)+(($width/2)*$bar) +2, (($height-$width) - ($height-$width)*($k/100)) - (ImageFontHeight($font)/2), sprintf( "%2d", $k),$tx); } // Add % over BULB $pct = sprintf( "%1.1f%%", ($current/$goal)*100 ); ImageString( $image, $font+2, ($width/2)-((strlen($pct)/2)*ImageFontWidth($font+2)), ($height-($width/2))-(ImageFontHeight($font+2) / 2), $pct, $bg); // send the image header("content-type: image/png"); if ($current < $goal) imagepng($image); else { // set up array of points for polygon $values = array( ($width*.33), $width, // Point 1 (x, y) 0, ($width*.33), // Point 2 (x, y) ($width*.33), ($width*.66), // Point 3 (x, y) $width*.33, 0, // Point 4 (x, y) $width*.5, $width*.33, // Point 5 (x, y) $width*.66, 0, // Point 6 (x, y) $width*.66, $width*0.66, // Point 7 (x, y) $width, $width*0.33, // Point 8 (x, y) $width*.66, $width // Point 9 (x, y) ); // create image $image2 = imagecreate($width, $height+$width); // Add room for thermometer blowing out the top ImageFilledRectangle($image2,0,0,$width,$height+$width,$bg); imagecopy ( $image2, $image, 0, $width, 0, 0, $width, $height ); // some colors // $bg = imagecolorallocate($image2, 200, 200, 200); $blue = imagecolorallocate($image2, 0, 0, 255); // draw a polygon imagepolygon($image2, $values, 9, $fg); ImageString( $image2, $font+6, 8, 20, 'Goal is', $blue ); if ($current == $goal) ImageString( $image2, $font+6, 5, 40, 'Reached!', $blue ); else ImageString( $image2, $font+6, 2, 40, 'Exceeded!', $blue ); // flush image imagepng($image2); imagedestroy($image2); } imagedestroy($image); } thermGraph( $HTTP_GET_VARS["Current"], $HTTP_GET_VARS["Goal"], $HTTP_GET_VARS["Width"], $HTTP_GET_VARS["Height"], $HTTP_GET_VARS["Font"] ); ?>