Example #1
0
        $border = ImageColorAllocate($image, 0, 0, 0);
        $fill = ImageColorAllocate($image, 0, 235, 0);
        ImageFilledRectangle($image, 0, 0, 101, 14, $back);
        ImageFilledRectangle($image, 1, 1, $rating / $max * 100, 14, $fill);
        ImageRectangle($image, 0, 0, 101, 14, $border);
        $textcolor = imagecolorallocate($image, 0, 0, 0);
        imagestring($image, 5, 35, 0, $rating / $max * 100 . '%', $textcolor);
    } else {
        if ($rating > $max) {
            $rating = $max;
        }
        $image = imagecreatetruecolor(10 * ($rating + 2) + 2, 15);
        $back = ImageColorAllocate($image, 250, 250, 250);
        $border = ImageColorAllocate($image, 0, 0, 0);
        $fill = ImageColorAllocate($image, 235, 0, 0);
        ImageFilledRectangle($image, 0, 0, 10 * ($rating + 2) + 1, 14, $back);
        ImageFilledRectangle($image, 1, 1, 10 * $rating, 14, $fill);
        ImageRectangle($image, 0, 0, 10 * $rating + 1, 14, $border);
        $textcolor = imagecolorallocate($image, 0, 0, 0);
        imagestring($image, 5, 10 * ($rating + 1), 0, $rating, $textcolor);
    }
    imagepng($image);
    imagedestroy($image);
}
Header("Content-type: image/png");
$rating = isset($_GET['rating']) ? $_GET['rating'] : 0;
if ($_GET['type'] == 'priority') {
    drawRating($rating, 10, 1);
} else {
    drawRating($rating, 100, 0);
}
Example #2
0
    $height = $_GET['height'];
    if ($width == 0) {
        $width = 200;
    }
    if ($height == 0) {
        $height = 7;
    }
    $rating = $_GET['rating'];
    $ratingbar = $rating / 100 * $width - 2;
    $image = imagecreate($width, $height);
    $fill = ImageColorAllocate($image, 0, 255, 0);
    if ($rating > 49) {
        $fill = ImageColorAllocate($image, 255, 255, 0);
    }
    if ($rating > 74) {
        $fill = ImageColorAllocate($image, 255, 128, 0);
    }
    if ($rating > 89) {
        $fill = ImageColorAllocate($image, 255, 0, 0);
    }
    $back = ImageColorAllocate($image, 205, 205, 205);
    $border = ImageColorAllocate($image, 0, 0, 0);
    ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back);
    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $fill);
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border);
    imagePNG($image);
    imagedestroy($image);
}
Header("Content-type: image/png");
drawRating();
Example #3
0
<?php

//this needs to reside in its own php page
//you can include that php page in your html as you would an image:
//<IMG SRC="ratingpng.php?rating=25.2" border="0">
function drawRating($rating, $border)
{
    $image = @imagecreate(102, 10);
    $back = ImageColorAllocate($image, 255, 255, 255);
    $border = ImageColorAllocate($image, 0, 0, 0);
    $red = ImageColorAllocate($image, 255, 60, 75);
    $fill = ImageColorAllocate($image, 44, 81, 150);
    imagefilledrectangle($image, 0, 0, 101, 9, $back);
    imagefilledrectangle($image, 1, 1, $rating, 9, $fill);
    imagerectangle($image, 0, 0, 101, 9, $border);
    imagepng($image);
    imagedestroy($image);
}
if (isset($_REQUEST['rating'])) {
    header("Content-Type: image/png");
    drawRating($_REQUEST['rating'], 0);
}
Example #4
0
function gd_progress_bar($width, $height, $progress, $title, $font, $out_of_lim_str, $out_of_lim_image, $mode = 1, $fontsize = 10)
{
    if ($out_of_lim_str === false) {
        $out_of_lim_str = "Out of limits";
    }
    if ($out_of_lim_image === false) {
        $out_of_lim_image = "images_graphs/outlimits.png";
    }
    // Copied from the PHP manual:
    // http://us3.php.net/manual/en/function.imagefilledrectangle.php
    // With some adds from sdonie at lgc dot com
    // Get from official documentation PHP.net website. Thanks guys :-)
    function drawRating($rating, $width, $height, $font, $out_of_lim_str, $mode, $fontsize)
    {
        global $config;
        global $REMOTE_ADDR;
        if ($width == 0) {
            $width = 150;
        }
        if ($height == 0) {
            $height = 20;
        }
        //$rating = $_GET['rating'];
        $ratingbar = $rating / 100 * $width - 2;
        $image = imagecreate($width, $height);
        //colors
        $back = ImageColorAllocate($image, 255, 255, 255);
        imagecolortransparent($image, $back);
        $border = ImageColorAllocate($image, 174, 174, 174);
        $text = ImageColorAllocate($image, 74, 74, 74);
        $red = ImageColorAllocate($image, 255, 60, 75);
        $green = ImageColorAllocate($image, 50, 205, 50);
        $blue = ImageColorAllocate($image, 255, 127, 0);
        $soft_green = ImageColorAllocate($image, 176, 255, 84);
        $soft_yellow = ImageColorAllocate($image, 255, 230, 84);
        $soft_red = ImageColorAllocate($image, 255, 154, 84);
        $other_red = ImageColorAllocate($image, 238, 0, 0);
        ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back);
        switch ($mode) {
            case 0:
                if ($rating > 70) {
                    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $soft_green);
                } elseif ($rating > 50) {
                    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $soft_yellow);
                } elseif ($rating > 30) {
                    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $soft_red);
                } else {
                    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $other_red);
                }
                ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border);
                break;
            case 1:
                if ($rating > 100) {
                    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $red);
                } elseif ($rating == 100) {
                    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $green);
                } else {
                    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $blue);
                }
                ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border);
                if ($rating > 50) {
                    if ($rating > 100) {
                        ImageTTFText($image, $fontsize, 0, $width / 4, $height / 2 + $height / 5, $back, $font, $out_of_lim_str);
                    } else {
                        ImageTTFText($image, $fontsize, 0, $width / 2 - $width / 10, $height / 2 + $height / 5, $back, $font, $rating . "%");
                    }
                } else {
                    ImageTTFText($image, $fontsize, 0, $width / 2 - $width / 10, $height / 2 + $height / 5, $text, $font, $rating . "%");
                }
                break;
            case 2:
                if ($rating > 70) {
                    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $other_red);
                } elseif ($rating > 50) {
                    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $soft_red);
                } elseif ($rating > 30) {
                    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $soft_yellow);
                } else {
                    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $soft_green);
                }
                ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border);
                break;
        }
        imagePNG($image);
        imagedestroy($image);
    }
    Header("Content-type: image/png");
    switch ($mode) {
        case 0:
            drawRating($progress, $width, $height, $font, $out_of_lim_str, $mode, $fontsize);
            /*
            if ($mode == 0) {
            		$engine->background_color = '#E6E6D2';
            		$engine->show_title = false;
            		if ($progress > 70) 
            			$color = '#B0FF54';
            		elseif ($progress > 50)
            			$color = '#FFE654';
            		elseif ($progress > 30)
            			$color = '#FF9A54';
            		else
            			$color = '#EE0000';
            	} else {
            		$engine->background_color = '#FFFFFF';
            		$engine->show_title = true;
            		$engine->title = format_numeric ($progress).' %';
            		$color = '#2C5196';
            	}
            */
            break;
        case 1:
            if ($progress > 100 || $progress < 0) {
                // HACK: This report a static image... will increase render in about 200% :-) useful for
                // high number of realtime statusbar images creation (in main all agents view, for example
                $imgPng = imageCreateFromPng($out_of_lim_image);
                imageAlphaBlending($imgPng, true);
                imageSaveAlpha($imgPng, true);
                imagePng($imgPng);
            } else {
                drawRating($progress, $width, $height, $font, $out_of_lim_str, $mode, 6);
            }
            break;
        case 2:
            if ($progress > 100 || $progress < 0) {
                // HACK: This report a static image... will increase render in about 200% :-) useful for
                // high number of realtime statusbar images creation (in main all agents view, for example
                $imgPng = imageCreateFromPng($out_of_lim_image);
                imageAlphaBlending($imgPng, true);
                imageSaveAlpha($imgPng, true);
                imagePng($imgPng);
            } else {
                drawRating($progress, $width, $height, $font, $out_of_lim_str, $mode, 6);
            }
            break;
    }
}
Example #5
0
function drawRating($rating) {
   $width = $_GET['width'];
   $height = $_GET['height'];
   if ($width == 0) {
     $width = 102;
   }
   if ($height == 0) {
     $height = 10;
   }

   $rating = $_GET['rating'];
   $ratingbar = (($rating/100)*$width)-2;

   $image = imagecreate($width,$height);
   //colors
   $back = ImageColorAllocate($image,255,255,255);
   $border = ImageColorAllocate($image,0,0,0);
   $red = ImageColorAllocate($image,255,60,75);
   $fill = ImageColorAllocate($image,44,81,150);

   ImageFilledRectangle($image,0,0,$width-1,$height-1,$back);
   ImageFilledRectangle($image,1,1,$ratingbar,$height-1,$fill);
   ImageRectangle($image,0,0,$width-1,$height-1,$border);
   imagePNG($image);
   imagedestroy($image);
}

Header("Content-type: image/png");
drawRating($rating);

?>
Example #6
0
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */
function drawRating($rating)
{
    $width = 300;
    $height = 15;
    $ratingbar = $rating / 100 * $width - 2;
    $image = imagecreate($width, $height);
    $fill = ImageColorAllocate($image, 67, 219, 0);
    if ($rating > 74) {
        $fill = ImageColorAllocate($image, 233, 233, 0);
    }
    if ($rating > 89) {
        $fill = ImageColorAllocate($image, 197, 6, 6);
    }
    if ($rating > 100) {
        echo "Overload Error!";
        exit;
    }
    $back = ImageColorAllocate($image, 255, 255, 255);
    $border = ImageColorAllocate($image, 151, 151, 151);
    ImageFilledRectangle($image, 0, 0, $width - 1, $height - 1, $back);
    ImageFilledRectangle($image, 1, 1, $ratingbar, $height - 1, $fill);
    ImageRectangle($image, 0, 0, $width - 1, $height - 1, $border);
    imagePNG($image);
    imagedestroy($image);
}
Header("Content-type: image/png");
drawRating($_GET['rating']);