Example #1
2
 function generateImage($token)
 {
     $iFont = 5;
     // Font ID
     $iSpacing = 2;
     // Spacing between characters
     $iDisplacement = 5;
     // Vertical chracter displacement
     // Establish font metric and image size
     $iCharWidth = ImageFontWidth($iFont);
     $iCharHeight = ImageFontHeight($iFont);
     $iWidth = strlen($token) * ($iCharWidth + $iSpacing);
     $iHeight = $iCharHeight + 2 * $iDisplacement;
     // Create the image
     $pic = ImageCreate($iWidth, $iHeight);
     // Allocate a background and foreground colour
     $col = array('white' => ImageColorAllocate($pic, 255, 255, 255), 'blue' => ImageColorAllocate($pic, 45, 45, 100), 'green' => ImageColorAllocate($pic, 45, 100, 45), 'red' => ImageColorAllocate($pic, 100, 45, 45), 'purple' => ImageColorAllocate($pic, 100, 45, 100), 'grey' => ImageColorAllocate($pic, 225, 225, 225), 'grey2' => ImageColorAllocate($pic, 200, 200, 200));
     for ($x = 0; $x < $iWidth; $x += 2) {
         for ($y = 0; $y < $iHeight; $y += 2) {
             ImageSetPixel($pic, $x, $y, $col['grey']);
         }
     }
     $iX = 1;
     for ($i = 0; $i < strlen($token); $i++) {
         ImageChar($pic, $iFont - 1, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col['grey2']);
         $iX += $iCharWidth + $iSpacing;
     }
     $iX = 2;
     $c = array('blue', 'green', 'red', 'purple');
     for ($i = 0; $i < strlen($token); $i++) {
         $colour = $c[rand(0, count($c) - 1)];
         ImageChar($pic, $iFont, $iX, $iDisplacement - rand(-$iDisplacement, $iDisplacement), $token[$i], $col[$colour]);
         $iX += $iCharWidth + $iSpacing;
     }
     for ($x = 1; $x < $iWidth; $x += 4) {
         for ($y = 1; $y < $iHeight; $y += 4) {
             ImageSetPixel($pic, $x, $y, $col['white']);
         }
     }
     // Draw some lines
     for ($i = 0; $i < 4; $i++) {
         ImageLine($pic, rand(0, $iWidth / 2), rand(0, $iHeight / 2), rand($iWidth / 2, $iWidth), rand($iHeight / 2, $iHeight), $col['white']);
     }
     ob_start();
     if (function_exists('imagejpeg')) {
         ImageJPEG($pic);
     } elseif (function_exists('imagepng')) {
         ImagePNG($pic);
     } else {
         ob_end_clean();
         return false;
     }
     $data = ob_get_contents();
     ob_end_clean();
     ImageDestroy($pic);
     return $data;
 }
Example #2
0
 function create($varDesc, $varValues)
 {
     Header("Content-type: image/png");
     $image = ImageCreate($this->imageWidth, $this->imageHeight);
     $bgcolor = ImageColorAllocate($image, $this->bgR, $this->bgG, $this->bgB);
     $white = ImageColorAllocate($image, 255, 255, 255);
     $black = ImageColorAllocate($image, 0, 0, 0);
     ImageFill($image, 0, 0, $bgcolor);
     $num = 0;
     foreach ($varDesc as $v) {
         $r = rand(0, 255);
         $g = rand(0, 255);
         $b = rand(0, 255);
         $sliceColors[$num] = ImageColorAllocate($image, $r, $g, $b);
         $num++;
     }
     // now $num has the number of elements
     // draw the box
     ImageLine($image, 0, 0, $this->imageWidth - 1, 0, $black);
     ImageLine($image, $this->imageWidth - 1, 0, $this->imageWidth - 1, $this->imageHeight - 1, $black);
     ImageLine($image, $this->imageWidth - 1, $this->imageHeight - 1, 0, $this->imageHeight - 1, $black);
     ImageLine($image, 0, $this->imageHeight - 1, 0, 0, $black);
     $total = 0;
     for ($x = 0; $x < $num; $x++) {
         $total += $varValues[$x];
     }
     // convert each slice into corresponding percentage of 360-degree circle
     for ($x = 0; $x < $num; $x++) {
         $angles[$x] = $varValues[$x] / $total * 360;
     }
     for ($x = 0; $x < $num; $x++) {
         // calculate and draw arc corresponding to each slice
         ImageArc($image, $this->imageWidth / 4, $this->imageHeight / 2, $this->imageWidth / 3, $this->imageHeight / 3, $angle, $angle + $angles[$x], $sliceColors[$x]);
         $angle = $angle + $angles[$x];
         $x1 = round($this->imageWidth / 4 + $this->imageWidth / 3 * cos($angle * pi() / 180) / 2);
         $y1 = round($this->imageHeight / 2 + $this->imageHeight / 3 * sin($angle * pi() / 180) / 2);
         // demarcate slice with another line
         ImageLine($image, $this->imageWidth / 4, $this->imageHeight / 2, $x1, $y1, $sliceColors[$x]);
     }
     // fill in the arcs
     $angle = 0;
     for ($x = 0; $x < $num; $x++) {
         $x1 = round($this->imageWidth / 4 + $this->imageWidth / 3 * cos(($angle + $angles[$x] / 2) * pi() / 180) / 4);
         $y1 = round($this->imageHeight / 2 + $this->imageHeight / 3 * sin(($angle + $angles[$x] / 2) * pi() / 180) / 4);
         ImageFill($image, $x1, $y1, $sliceColors[$x]);
         $angle = $angle + $angles[$x];
     }
     // put the desc strings
     ImageString($image, 5, $this->imageWidth / 2, 60, "Legend", $black);
     for ($x = 0; $x < $num; $x++) {
         $fl = sprintf("%.2f", $varValues[$x] * 100 / $total);
         $str = $varDesc[$x] . " (" . $fl . "%)";
         ImageString($image, 3, $this->imageWidth / 2, ($x + 5) * 20, $str, $sliceColors[$x]);
     }
     // put the title
     ImageString($image, 5, 20, 20, $this->title, $black);
     ImagePng($image);
     ImageDestroy($image);
 }
Example #3
0
function drawLines($image, $w, $h, $col, $top, $right, $left, $bottom)
{
    $gHeight = $h - ($top + $bottom);
    $space = $gHeight / 4;
    $y = $top;
    for ($a = 1; $a < 5; $a++) {
        ImageLine($image, $left, $y, $w - $right, $y, $col);
        $y = $y + $space;
    }
}
 function display($db_object, $common, $user_id, $default, $error_msg, $learning, $post_var)
 {
     $width = 340;
     $height = 220;
     //	$labelfont = '2';
     $labeltitlefont = '3';
     $image = ImageCreate($width, $height);
     while (list($kk, $vv) = @each($post_var)) {
         ${$kk} = $vv;
     }
     /*
     $to_date=2004-01-02;
     $from_date=2004-01-02;
     $avg_rater=50.23;
     */
     $bgcolor = ImageColorAllocate($image, 0xffffff, 0xffffff, 0xffffff);
     $border = ImageColorAllocate($image, 0x0, 0x0, 0x0);
     $border1 = ImageColorAllocate($image, 0xcccccc, 0x0, 0x0);
     //$border2 = ImageColorAllocate($image,0x000000, 0xcccccc, 0x000000);
     ImageRectangle($image, 40, 20, 240, 160, $border);
     ImageString($image, $labelfont, 15, 20, "100%", $border);
     ImageString($image, $labelfont, 20, 55, "75%", $border);
     ImageString($image, $labelfont, 20, 90, "50%", $border);
     ImageString($image, $labelfont, 20, 125, "25%", $border);
     ImageString($image, $labelfont, 20, 155, "0%", $border);
     $fdate = $learning->changedate_display($from_date);
     $tdate = $learning->changedate_display($to_date);
     $days = $error_msg['cDays'] . " {$fdate} " . $error_msg['cTo'] . " {$tdate} ";
     $avg_rt = @explode(",", $avg_rater);
     $id = @explode(",", $ids);
     for ($i = 0; $i < count($avg_rt); $i++) {
         $p1 = rand(0, 200);
         $p2 = rand(30, 250);
         $p3 = rand(100, 250);
         $color = imagecolorallocate($image, $p1, $p2, $p3);
         $avg = $avg_rt[$i];
         $avg_comp = 160 - 140 / 100 * $avg;
         $avg = round($avg, 2);
         $rid = $id[$i];
         $rname = $common->name_display($db_object, $rid);
         ImageStringUp($image, $labeltitlefont, 5, 110, $error_msg['cResults'], $border);
         ImageString($image, $labeltitlefont, 245, 20, $error_msg['cCommitment'], $border);
         ImageString($image, $labeltitlefont, 50, 170, "{$days}", $border);
         //ImageString($image, $labeltitlefont, 50,180, "$rname", $color);
         ImageLine($image, 240, 20, 40, 160, $border1);
         //COMMITMENT LINE
         ImageLine($image, 240, $avg_comp, 40, 160, $color);
         //AVERAGE COMPLETION
         header("Content-type: image/png");
         // or "Content-type: image/png"
         Imagepng($image);
         // or imagepng($image)
     }
     ImageDestroy($image);
 }
Example #5
0
 function callback($img, $arg)
 {
     #fwrite(STDERR, "callback in object: arg=" . print_r($arg, True) . "\nimg=" . print_r($img, True) . "\n");
     # fwrite(STDERR, print_r($this, True));
     #fwrite(STDERR, "Plot area: ({$this->plot_area[0]}, {$this->plot_area[1]}) :");
     #fwrite(STDERR, " ({$this->plot_area[2]}, {$this->plot_area[2]})\n");
     # Draw an X across the plot area.
     $red = ImageColorResolve($img, 255, 0, 0);
     ImageLine($img, $this->plot_area[0], $this->plot_area[1], $this->plot_area[2], $this->plot_area[3], $red);
     ImageLine($img, $this->plot_area[0], $this->plot_area[3], $this->plot_area[2], $this->plot_area[1], $red);
 }
Example #6
0
/**
 * MaxSite CMS
 * (c) http://max-3000.com/
 */
function _create_captha_img()
{
    $width = 100;
    $height = 25;
    $im = @imagecreate($width, $height) or die("Cannot initialize new GD image stream!");
    if (isset($_GET['image']) and isset($_GET['page'])) {
        $char = md5($_GET['image'] . $_GET['page']);
    } else {
        die("error");
    }
    $char = str_replace(array('a', 'b', 'c', 'd', 'e', 'f'), array('0', '5', '8', '3', '4', '7'), $char);
    $char = substr($char, 1, 4);
    imagecolortransparent($im, imagecolorallocate($im, 205, 255, 255));
    // rnd
    for ($i = 0; $i < strlen($char); $i++) {
        // $text_color = imagecolorallocate ($im, rand(220,255), rand(0,40), 120);
        $text_color = imagecolorallocate($im, 255, 0, 0);
        $x = $width / 10 + $i * ($width / 5);
        // $y = rand(0, 5);
        $y = 0;
        imagechar($im, 4, $x, $y, chr(rand(49, 90)), $text_color);
    }
    $point_color = imagecolorallocate($im, 255, 120, 120);
    ImageLine($im, 3, 9, 150, 2, $point_color);
    //output characters
    for ($i = 0; $i < strlen($char); $i++) {
        $text_color = imagecolorallocate($im, rand(0, 120), rand(0, 180), rand(0, 180));
        // $x = 5 + $i * 40 + rand(-5, 5);
        $x = 3 + $i * $width / 4;
        //$y = rand(0, 5);
        $y = 10;
        imagechar($im, 5, $x, $y, $char[$i], $text_color);
    }
    //ouput PNG
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    // HTTP/1.1
    header("Cache-Control: no-store, no-cache, must-revalidate");
    header("Cache-Control: post-check=0, pre-check=0", false);
    header("Pragma: no-cache");
    //	HTTP/1.0
    if (function_exists("imagepng")) {
        header("Content-type: image/png");
        imagepng($im);
    } elseif (function_exists("imagegif")) {
        header("Content-type: image/gif");
        imagegif($im);
    } elseif (function_exists("imagejpeg")) {
        header("Content-type: image/jpeg");
        imagejpeg($im);
    } else {
        die("No image support in this PHP server!");
    }
    imagedestroy($im);
}
function show_gd_img($content = "")
{
    $content = '  ' . preg_replace("/(\\w)/", "\\1 ", $content) . ' ';
    $gd_version = 2;
    @header("Content-Type: image/jpeg");
    $tmp_x = 140;
    $tmp_y = 20;
    $image_x = 210;
    $image_y = 65;
    $circles = 3;
    if ($gd_version == 1) {
        $tmp = imagecreate($tmp_x, $tmp_y);
        $im = imagecreate($image_x, $image_y);
    } else {
        $tmp = imagecreatetruecolor($tmp_x, $tmp_y);
        $im = imagecreatetruecolor($image_x, $image_y);
    }
    $white = ImageColorAllocate($tmp, 255, 255, 255);
    $black = ImageColorAllocate($tmp, 0, 0, 0);
    $grey = ImageColorAllocate($tmp, 210, 210, 210);
    imagefill($tmp, 0, 0, $white);
    for ($i = 1; $i <= $circles; $i++) {
        $values = array(0 => rand(0, $tmp_x - 10), 1 => rand(0, $tmp_y - 3), 2 => rand(0, $tmp_x - 10), 3 => rand(0, $tmp_y - 3), 4 => rand(0, $tmp_x - 10), 5 => rand(0, $tmp_y - 3), 6 => rand(0, $tmp_x - 10), 7 => rand(0, $tmp_y - 3), 8 => rand(0, $tmp_x - 10), 9 => rand(0, $tmp_y - 3), 10 => rand(0, $tmp_x - 10), 11 => rand(0, $tmp_y - 3));
        $randomcolor = imagecolorallocate($tmp, rand(100, 255), rand(100, 255), rand(100, 255));
        imagefilledpolygon($tmp, $values, 6, $randomcolor);
    }
    imagestring($tmp, 5, 0, 2, $content, $black);
    //-----------------------------------------
    // Distort by resizing
    //-----------------------------------------
    imagecopyresized($im, $tmp, 0, 0, 0, 0, $image_x, $image_y, $tmp_x, $tmp_y);
    imagedestroy($tmp);
    $white = ImageColorAllocate($im, 255, 255, 255);
    $black = ImageColorAllocate($im, 0, 0, 0);
    $grey = ImageColorAllocate($im, 100, 100, 100);
    $random_pixels = $image_x * $image_y / 10;
    for ($i = 0; $i < $random_pixels; $i++) {
        ImageSetPixel($im, rand(0, $image_x), rand(0, $image_y), $black);
    }
    $no_x_lines = ($image_x - 1) / 5;
    for ($i = 0; $i <= $no_x_lines; $i++) {
        // X lines
        ImageLine($im, $i * $no_x_lines, 0, $i * $no_x_lines, $image_y, $grey);
        // Diag lines
        ImageLine($im, $i * $no_x_lines, 0, $i * $no_x_lines + $no_x_lines, $image_y, $grey);
    }
    $no_y_lines = ($image_y - 1) / 5;
    for ($i = 0; $i <= $no_y_lines; $i++) {
        ImageLine($im, 0, $i * $no_y_lines, $image_x, $i * $no_y_lines, $grey);
    }
    ImageJPEG($im);
    ImageDestroy($im);
    exit;
}
Example #8
0
function linealfa ($alfa, $alfaold, $numcolor)
{
	global $xsize, $ysize, $im, $black, $color;
	$gradus = ($alfa + $alfaold)/2;
	$alfa = ($alfa * pi())/180;
	$x = $xsize/2 + ($xsize/2) * sin($alfa);
	$y = $ysize/2 - ($xsize/2) * cos($alfa);
	ImageLine($im, $xsize/2, $ysize/2, $x, $y, $black);

	$gradus = ($gradus * pi())/180;
	$x = $xsize/2 + ($xsize/3) * sin($gradus);
	$y = $ysize/2 - ($ysize/3) * cos($gradus);
	if ($gradus!=0) ImageFill($im, $x, $y, $color[$numcolor]);
}
Example #9
0
    /**
     * Output the plot
     * @access private
     */
    function _done()
    {
        parent::_done();

        $p1 = false;
        $this->_dataset->_reset();
        while ($point = $this->_dataset->_next()) {
            $p2['X'] = $this->_parent->_pointX($point);
            $p2['Y'] = $this->_parent->_pointY($point);
            if ($p1) {
                ImageLine($this->_canvas(), $p1['X'], $p1['Y'], $p2['X'], $p2['Y'], $this->_getLineStyle());
            }
            $p1 = $p2;
        }
        $this->_drawMarker();
    }
Example #10
0
 function Generate()
 {
     $im = imagecreate(100, 50);
     $background_color = imagecolorallocate($im, 200, 200, 200);
     $text_color = imagecolorallocate($im, 233, 14, 91);
     $text_color = imagecolorallocate($im, 233, 14, 91);
     $_SESSION['SPAM_CHECKER_TEXT'] = substr(md5(time()), 4, 6);
     for ($i = 0; $i < rand(15, 20); $i++) {
         ImageLine($im, rand(0, 100), rand(0, 50), rand(0, 100), rand(0, 50), imagecolorallocate($im, rand(100, 150), rand(100, 150), rand(100, 150)));
     }
     $i = 1;
     for ($i = 0; $i < strlen($_SESSION['SPAM_CHECKER_TEXT']); $i++) {
         $text_color = imagecolorallocate($im, rand(10, 50), rand(10, 50), rand(10, 50));
         imagettftext($im, rand(12, 15), rand(0, 20), 15 + $i * 15, rand(20, 35), $text_color, "arial.ttf", $_SESSION['SPAM_CHECKER_TEXT'][$i]);
     }
     header("Content-type: image/jpg");
     imagejpeg($im);
     imagedestroy($im);
 }
Example #11
0
 function createGistagramm($width, $heigth)
 {
     $image = @imagecreate($width, $heigth);
     $maxKey = findMaxKey($this->array);
     $maxValue = findMaxValue($this->array);
     ImageColorAllocate($image, 255, 255, 255);
     ImageLine($image, $this->align, $heigth - $this->align, $width - $this->align, $heigth - $this->align, 1);
     ImageLine($image, $this->align, $this->align, $this->align, $heigth - $this->align, 1);
     $widthRect = round(($width - 2 * $this->align) / ($maxKey + 1)) * $this->widthColumn;
     foreach ($this->array as $key => $value) {
         $color = getColor($image, $value, $maxValue);
         $heigthRect = round($value * ($heigth - 2 * $this->align) / $maxValue);
         $pos = round($key / ($maxKey + 1) * ($width - 2 * $this->align)) + $this->align;
         ImageFilledRectangle($image, $pos - $widthRect / 2, $heigth - $heigthRect, $pos + $widthRect / 2, $heigth - $this->align, $color);
         ImageString($image, 0, $pos - $widthRect / 2, $heigth - $heigthRect - 10, $value, 1);
         ImageString($image, 0, $pos - $widthRect / 2, $heigth - $this->align, $key, 1);
     }
     $this->image = $image;
 }
Example #12
0
 public function guvenlikKodu()
 {
     $kod = substr(md5(rand(0, 999999999999.0)), -6);
     if ($kod) {
         $this->session->set_userdata("guvKod", $kod);
         $width = 100;
         $height = 30;
         $resim = ImageCreate($width, $height);
         $beyaz = ImageColorAllocate($resim, 255, 255, 255);
         $rand = ImageColorAllocate($resim, rand(0, 255), rand(0, 255), rand(0, 255));
         ImageFill($resim, 0, 0, $rand);
         ImageString($resim, 5, 24, 7, $this->session->userdata("guvKod"), $beyaz);
         ImageLine($resim, 100, 19, 0, 19, $beyaz);
         header("Content,type:image/png");
         ImagePng($resim);
         ImageDestroy($resim);
         $this->session->set_userdata("guvKod2", $this->session->userdata("guvKod"));
     }
 }
Example #13
0
function cs_captcha($hash)
{
    $gd_info = gd_info();
    $chars = strlen($hash);
    $height = $chars == 3 ? 18 : 40;
    $charsize = $chars * 20;
    $img = ImageCreateTrueColor($charsize, $height);
    $bgc = ImageColorAllocate($img, rand(0, 80), rand(0, 80), rand(0, 80));
    ImageFill($img, 0, 0, $bgc);
    for ($i = 1; $i < $chars; $i++) {
        $linecolor = ImageColorAllocate($img, rand(0, 150), rand(0, 150), rand(0, 150));
        ImageLine($img, $i * 20, 0, $i * 20, $height, $linecolor);
    }
    $linecolor = ImageColorAllocate($img, rand(0, 150), rand(0, 150), rand(0, 150));
    ImageLine($img, 0, $height / 3, $charsize, $height / 3, $linecolor);
    $linecolor = ImageColorAllocate($img, rand(0, 150), rand(0, 150), rand(0, 150));
    ImageLine($img, 0, $height / 3 * 2, $charsize, $height / 3 * 2, $linecolor);
    $linecolor = ImageColorAllocate($img, 0, 0, 0);
    ImageLine($img, 0, 0, $charsize, 0, $linecolor);
    ImageLine($img, 0, $height - 1, $charsize, $height - 1, $linecolor);
    ImageLine($img, 0, 0, 0, $height - 1, $linecolor);
    ImageLine($img, $charsize - 1, 0, $charsize - 1, $height - 1, $linecolor);
    for ($i = 0; $i < $chars; $i++) {
        $textcolor = ImageColorAllocate($img, rand(100, 250), rand(100, 250), rand(100, 250));
        ImageString($img, rand(3, 5), rand($i * 20 + 2, $i * 20 + 8), rand(2, $height - 20), $hash[$i], $textcolor);
    }
    # disable browser / proxy caching
    header("Cache-Control: max-age=0, no-cache, no-store, must-revalidate");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    if (!empty($gd_info["PNG Support"])) {
        header("Content-type:image/png");
        ImagePNG($img);
    } elseif (!empty($gd_info["JPG Support"]) or !empty($gd_info["JPEG Support"])) {
        header("Content-type:image/jpg");
        ImageJPEG($img);
    } elseif (!empty($gd_info["GIF Create Support"])) {
        header("Content-type:image/gif");
        ImageGIF($img);
    } else {
        cs_error(__FILE__, 'Could not create image file using GD');
    }
}
 function display($db_object, $common, $user_id, $default, $error_msg, $learning, $post_var)
 {
     $width = 340;
     $height = 220;
     //	$labelfont = '2';
     $labeltitlefont = '3';
     $image = ImageCreate($width, $height);
     while (list($kk, $vv) = @each($post_var)) {
         ${$kk} = $vv;
     }
     $bgcolor = ImageColorAllocate($image, 0xffffff, 0xffffff, 0xffffff);
     $border = ImageColorAllocate($image, 0x0, 0x0, 0x0);
     $border1 = ImageColorAllocate($image, 0xcccccc, 0x0, 0x0);
     $border2 = ImageColorAllocate($image, 0x0, 0xcccccc, 0x0);
     ImageRectangle($image, 40, 20, 240, 160, $border);
     ImageString($image, $labelfont, 15, 20, "100%", $border);
     ImageString($image, $labelfont, 20, 55, "75%", $border);
     ImageString($image, $labelfont, 20, 90, "50%", $border);
     ImageString($image, $labelfont, 20, 125, "25%", $border);
     ImageString($image, $labelfont, 20, 155, "0%", $border);
     $fdate = $learning->changedate_display($from_date);
     $tdate = $learning->changedate_display($to_date);
     $days = $error_msg['cDays'] . " {$fdate} " . $error_msg['cTo'] . " {$tdate} ";
     $avg_comp = 160 - 140 / 100 * $avg;
     $avg = round($avg, 2);
     ImageStringUp($image, $labeltitlefont, 5, 110, $error_msg['cResults'], $border);
     ImageString($image, $labeltitlefont, 245, 20, $error_msg['cCommitment'], $border);
     ImageString($image, $labeltitlefont, 50, 170, "{$days}", $border);
     ImageString($image, $labeltitlefont, 50, 200, $error_msg['cCTimelyCompletionofActivities'], $border);
     ImageString($image, $labeltitlefont, 50, 185, $error_msg['cAverage'], $border);
     ImageString($image, $labeltitlefont, 115, 185, $avg, $border);
     ImageLine($image, 240, 20, 40, 160, $border1);
     //COMMITMENT LINE
     ImageLine($image, 240, $avg_comp, 40, 160, $border2);
     //AVERAGE COMPLETION
     ImageString($image, $labeltitlefont, 245, $avg_comp, $error_msg['cAccomplishment'], $border);
     header("Content-type: image/png");
     // or "Content-type: image/png"
     Imagepng($image);
     // or imagepng($image)
     ImageDestroy($image);
 }
Example #15
0
function createImage($text, $width, $height, $font = 5)
{
    global $fontColor, $bgColor, $lineColor;
    if ($img = @ImageCreate($width, $height)) {
        list($R, $G, $B) = convertRGB($fontColor);
        $fontColor = ImageColorAllocate($img, $R, $G, $B);
        list($R, $G, $B) = convertRGB($bgColor);
        $bgColor = ImageColorAllocate($img, $R, $G, $B);
        list($R, $G, $B) = convertRGB($lineColor);
        $lineColor = ImageColorAllocate($img, $R, $G, $B);
        ImageFill($img, 0, 0, $bgColor);
        for ($i = 0; $i <= $width; $i += 5) {
            @ImageLine($img, $i, 0, $i, $height, $lineColor);
        }
        for ($i = 0; $i <= $height; $i += 5) {
            @ImageLine($img, 0, $i, $width, $i, $lineColor);
        }
        $hcenter = $width / 2;
        $vcenter = $height / 2;
        $x = round($hcenter - ImageFontWidth($font) * strlen($text) / 2);
        $y = round($vcenter - ImageFontHeight($font) / 2);
        ImageString($img, $font, $x, $y, $text, $fontColor);
        if (function_exists('ImagePNG')) {
            header('Content-Type: image/png');
            @ImagePNG($img);
        } else {
            if (function_exists('ImageGIF')) {
                header('Content-Type: image/gif');
                @ImageGIF($img);
            } else {
                if (function_exists('ImageJPEG')) {
                    header('Content-Type: image/jpeg');
                    @ImageJPEG($img);
                }
            }
        }
        ImageDestroy($img);
    }
}
Example #16
0
 function print_image($text)
 {
     $w = 50;
     $image = imagecreate($w, 25);
     $light = ImageColorAllocate($image, 255, 255, 0);
     $dark = ImageColorAllocate($image, 0, 0, 0);
     $gray = ImageColorAllocate($image, 0, 0, 0);
     ImageFill($image, 0, 0, $light);
     $width_two = ImageFontWidth(5) * strlen($text);
     $height = ImageFontHeight(100);
     $width = ($w - $width_two) / 2;
     # vertical lines
     for ($x = 0; $x <= 100; $x += 10) {
         ImageLine($image, $x, 0, $x, 100, $dark);
     }
     # horizontal lines
     for ($x = 0; $x <= 100; $x += 10) {
         ImageLine($image, 0, $x, 100, $x, $dark);
     }
     ImageString($image, 5, $width, 4, $text, $dark);
     ImagePNG($image, '', 80);
     ImageDestroy($image);
 }
 function ellipse($bg_colour = "FFFFFF")
 {
     $this->bgc = $bg_colour;
     $this->br = $this->hex2rgb(substr($this->bgc, 0, 2));
     $this->bg = $this->hex2rgb(substr($this->bgc, 2, 2));
     $this->bb = $this->hex2rgb(substr($this->bgc, 4, 2));
     $this->dot = @ImageCreate(6, 6);
     $this->dot_base = @ImageColorAllocate($this->dot, $this->br, $this->bg, $this->bb);
     $this->zenitha = @ImageColorClosest($this->t, $this->br, $this->bg, $this->bb);
     for ($this->rad = 0; $this->rad < 6.3; $this->rad += 0.005) {
         $this->xpos = floor($this->q + sin($this->rad) * $this->q) / 2;
         $this->ypos = floor($this->r + cos($this->rad) * $this->r) / 2;
         $this->xto = 0;
         if ($this->xpos >= $this->q / 2) {
             $this->xto = $this->q;
         }
         @ImageCopyMerge($this->t, $this->dot, $this->xpos - 3, $this->ypos - 3, 0, 0, 6, 6, 30);
         @ImageCopyMerge($this->t, $this->dot, $this->xpos - 2, $this->ypos - 2, 0, 0, 4, 4, 30);
         @ImageCopyMerge($this->t, $this->dot, $this->xpos - 1, $this->ypos - 1, 0, 0, 2, 2, 30);
         @ImageLine($this->t, $this->xpos, $this->ypos, $this->xto, $this->ypos, $this->zenitha);
     }
     @ImageDestroy($this->dot);
 }
Example #18
0
 protected function drawElement(&$data, $from, $to, $minX, $maxX, $minY, $maxY, $drawtype, $max_color, $avg_color, $min_color, $minmax_color, $calc_fnc, $axisside)
 {
     if (!isset($data['max'][$from]) || !isset($data['max'][$to])) {
         return;
     }
     $oxy = $this->oxy[$axisside];
     $zero = $this->zero[$axisside];
     $unit2px = $this->unit2px[$axisside];
     $shift_min_from = $shift_min_to = 0;
     $shift_max_from = $shift_max_to = 0;
     $shift_avg_from = $shift_avg_to = 0;
     if (isset($data['shift_min'][$from])) {
         $shift_min_from = $data['shift_min'][$from];
     }
     if (isset($data['shift_min'][$to])) {
         $shift_min_to = $data['shift_min'][$to];
     }
     if (isset($data['shift_max'][$from])) {
         $shift_max_from = $data['shift_max'][$from];
     }
     if (isset($data['shift_max'][$to])) {
         $shift_max_to = $data['shift_max'][$to];
     }
     if (isset($data['shift_avg'][$from])) {
         $shift_avg_from = $data['shift_avg'][$from];
     }
     if (isset($data['shift_avg'][$to])) {
         $shift_avg_to = $data['shift_avg'][$to];
     }
     /**/
     $min_from = $data['min'][$from] + $shift_min_from;
     $min_to = $data['min'][$to] + $shift_min_to;
     $max_from = $data['max'][$from] + $shift_max_from;
     $max_to = $data['max'][$to] + $shift_max_to;
     $avg_from = $data['avg'][$from] + $shift_avg_from;
     $avg_to = $data['avg'][$to] + $shift_avg_to;
     $x1 = $from + $this->shiftXleft - 1;
     $x2 = $to + $this->shiftXleft;
     $y1min = $zero - ($min_from - $oxy) / $unit2px;
     $y2min = $zero - ($min_to - $oxy) / $unit2px;
     $y1max = $zero - ($max_from - $oxy) / $unit2px;
     $y2max = $zero - ($max_to - $oxy) / $unit2px;
     $y1avg = $zero - ($avg_from - $oxy) / $unit2px;
     $y2avg = $zero - ($avg_to - $oxy) / $unit2px;
     //*/
     switch ($calc_fnc) {
         case CALC_FNC_MAX:
             $y1 = $y1max;
             $y2 = $y2max;
             $shift_from = $shift_max_from;
             $shift_to = $shift_max_to;
             break;
         case CALC_FNC_MIN:
             $y1 = $y1min;
             $y2 = $y2min;
             $shift_from = $shift_min_from;
             $shift_to = $shift_min_to;
             break;
         case CALC_FNC_ALL:
             // MAX
             $y1x = $y1max > $this->sizeY + $this->shiftY || $y1max < $this->shiftY;
             $y2x = $y2max > $this->sizeY + $this->shiftY || $y2max < $this->shiftY;
             if ($y1x) {
                 $y1max = $y1max > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY;
             }
             if ($y2x) {
                 $y2max = $y2max > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY;
             }
             //--
             // MIN
             $y1n = $y1min > $this->sizeY + $this->shiftY || $y1min < $this->shiftY;
             $y2n = $y2min > $this->sizeY + $this->shiftY || $y2min < $this->shiftY;
             if ($y1n) {
                 $y1min = $y1min > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY;
             }
             if ($y2n) {
                 $y2min = $y2min > $this->sizeY + $this->shiftY ? $this->sizeY + $this->shiftY : $this->shiftY;
             }
             //--
             $a[0] = $x1;
             $a[1] = $y1max;
             $a[2] = $x1;
             $a[3] = $y1min;
             $a[4] = $x2;
             $a[5] = $y2min;
             $a[6] = $x2;
             $a[7] = $y2max;
             // don't use break, avg must be drawed in this statement
         // don't use break, avg must be drawed in this statement
         case CALC_FNC_AVG:
             // don't use break, avg must be drawed in this statement
         // don't use break, avg must be drawed in this statement
         default:
             $y1 = $y1avg;
             $y2 = $y2avg;
             $shift_from = $shift_avg_from;
             $shift_to = $shift_avg_to;
     }
     $shift_from -= $shift_from != 0 ? $oxy : 0;
     $shift_to -= $shift_to != 0 ? $oxy : 0;
     $y1_shift = $zero - $shift_from / $unit2px;
     $y2_shift = $zero - $shift_to / $unit2px;
     //*/
     if (!$this->limitToBounds($y1, $y2, $this->shiftY, $this->sizeY, $drawtype)) {
         return true;
     }
     if (!$this->limitToBounds($y1_shift, $y2_shift, $this->shiftY, $this->sizeY, $drawtype)) {
         return true;
     }
     // draw main line
     switch ($drawtype) {
         case GRAPH_ITEM_DRAWTYPE_BOLD_LINE:
             if ($calc_fnc == CALC_FNC_ALL) {
                 imagefilledpolygon($this->im, $a, 4, $minmax_color);
                 if (!$y1x || !$y2x) {
                     imageline($this->im, $x1 + 1, $y1max, $x2 + 1, $y2max, $max_color);
                     imageline($this->im, $x1, $y1max, $x2, $y2max, $max_color);
                 }
                 if (!$y1n || !$y2n) {
                     imageline($this->im, $x1 - 1, $y1min, $x2 - 1, $y2min, $min_color);
                     imageline($this->im, $x1, $y1min, $x2, $y2min, $min_color);
                 }
             }
             imageline($this->im, $x1, $y1 + 1, $x2, $y2 + 1, $avg_color);
             imageline($this->im, $x1, $y1, $x2, $y2, $avg_color);
             break;
         case GRAPH_ITEM_DRAWTYPE_LINE:
             if ($calc_fnc == CALC_FNC_ALL) {
                 imagefilledpolygon($this->im, $a, 4, $minmax_color);
                 if (!$y1x || !$y2x) {
                     imageline($this->im, $x1, $y1max, $x2, $y2max, $max_color);
                 }
                 if (!$y1n || !$y2n) {
                     imageline($this->im, $x1, $y1min, $x2, $y2min, $min_color);
                 }
             }
             imageline($this->im, $x1, $y1, $x2, $y2, $avg_color);
             break;
         case GRAPH_ITEM_DRAWTYPE_FILLED_REGION:
             //--
             $a[0] = $x1;
             $a[1] = $y1;
             $a[2] = $x1;
             $a[3] = $y1_shift;
             $a[4] = $x2;
             $a[5] = $y2_shift;
             $a[6] = $x2;
             $a[7] = $y2;
             imagefilledpolygon($this->im, $a, 4, $avg_color);
             break;
         case GRAPH_ITEM_DRAWTYPE_DOT:
             imagefilledrectangle($this->im, $x1 - 1, $y1 - 1, $x1, $y1, $avg_color);
             break;
         case GRAPH_ITEM_DRAWTYPE_BOLD_DOT:
             imagefilledrectangle($this->im, $x2 - 1, $y2 - 1, $x2 + 1, $y2 + 1, $avg_color);
             break;
         case GRAPH_ITEM_DRAWTYPE_DASHED_LINE:
             if (function_exists('imagesetstyle')) {
                 // Use imagesetstyle+imageline instead of bugged imagedashedline
                 $style = array($avg_color, $avg_color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT);
                 imagesetstyle($this->im, $style);
                 imageline($this->im, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);
             } else {
                 imagedashedline($this->im, $x1, $y1, $x2, $y2, $avg_color);
             }
             break;
         case GRAPH_ITEM_DRAWTYPE_GRADIENT_LINE:
             ImageLine($this->im, $x1, $y1, $x2, $y2, $avg_color);
             //draw the initial line
             ImageLine($this->im, $x1, $y1 - 1, $x2, $y2 - 1, $avg_color);
             $bitmask = 255;
             $blue = $avg_color & $bitmask;
             // $blue_diff = 255 - $blue;
             $bitmask = $bitmask << 8;
             $green = ($avg_color & $bitmask) >> 8;
             // $green_diff = 255 - $green;
             $bitmask = $bitmask << 8;
             $red = ($avg_color & $bitmask) >> 16;
             // $red_diff = 255 - $red;
             $maxAlpha = 110;
             $startAlpha = 50;
             $alphaRatio = $maxAlpha / ($this->sizeY - $startAlpha);
             $diffX = $x1 - $x2;
             for ($i = 0; $i <= $diffX; $i++) {
                 $Yincr = $diffX > 0 ? abs($y2 - $y1) / $diffX : 0;
                 $gy = $y1 > $y2 ? $y2 + $Yincr * $i : $y2 - $Yincr * $i;
                 $steps = $this->sizeY + $this->shiftY - $gy + 1;
                 for ($j = 0; $j < $steps; $j++) {
                     if ($gy + $j < $this->shiftY + $startAlpha) {
                         $alpha = 0;
                     } else {
                         $alpha = 127 - abs(127 - $alphaRatio * ($gy + $j - $this->shiftY - $startAlpha));
                     }
                     $color = imagecolorexactalpha($this->im, $red, $green, $blue, $alpha);
                     imagesetpixel($this->im, $x2 + $i, $gy + $j, $color);
                 }
             }
             break;
     }
 }
Example #19
0
    } else {
        if ($min % 5 == 0) {
            $len = $radius / 10;
        } else {
            $len = $radius / 25;
        }
    }
    $ang = 2 * M_PI * $min / 60;
    $x1 = sin($ang) * ($radius - $len) + $radius;
    $y1 = cos($ang) * ($radius - $len) + $radius;
    $x2 = 1 * sin($ang) * $radius;
    $y2 = 1 * cos($ang) * $radius;
    ImageLine($img, $x1, $y1, $x2, $y2, $color_black);
}
list($hour, $min, $sec) = preg_split("/-/", Date("h-i-s", time() - 3600));
$hour = $hour % 12;
$xs = intval(cos($sec * M_PI / 30 - M_PI / 2) * 0.75 * $radius + $radius);
$ys = intval(sin($sec * M_PI / 30 - M_PI / 2) * 0.75 * $radius + $radius);
$xm = intval(cos($min * M_PI / 30 - M_PI / 2) * 0.65 * $radius + $radius);
$ym = intval(sin($min * M_PI / 30 - M_PI / 2) * 0.65 * $radius + $radius);
$xh = intval(cos($hour * 5 * M_PI / 30 - M_PI / 2) * 0.5 * $radius + $radius);
$yh = intval(sin($hour * 5 * M_PI / 30 - M_PI / 2) * 0.5 * $radius + $radius);
ImageLine($img, $radius, $radius, $xs, $ys, $color_grey);
ImageLine($img, $radius, $radius - 1, $xm, $ym, $color_blue);
ImageLine($img, $radius - 1, $radius, $xm, $ym, $color_blue);
ImageLine($img, $radius, $radius - 1, $xh, $yh, $color_blue);
ImageLine($img, $radius - 1, $radius, $xh, $yh, $color_blue);
ImageArc($img, $radius, $radius, $radius / 8, $radius / 8, 0, 360, $color_red);
ImageFillToBorder($img, $radius, $radius, $color_red, $color_red);
ImageGif($img);
ImageDestroy($img);
Example #20
0
    /**
      * Draw a sample for use with legend
      * @param int $x The x coordinate to draw the sample at
      * @param int $y The y coordinate to draw the sample at
      * @access private
      */
    function _legendSample($x, $y, &$font)
    {
        if (is_a($this->_fillStyle, "Image_Graph_Fill")) {
            $fillStyle = $this->_fillStyle->_getFillStyleAt($x -5, $y -5, 10, 10);
        } else {
            $fillStyle = $this->_getFillStyle();
        }
        if ($fillStyle != IMG_COLOR_TRANSPARENT) {
            ImageFilledRectangle($this->_canvas(), $x -5, $y -5, $x +5, $y +5, $fillStyle);
            ImageRectangle($this->_canvas(), $x -5, $y -5, $x +5, $y +5, $this->_getLineStyle());
        } else {
            ImageLine($this->_canvas(), $x -7, $y, $x +7, $y, $this->_getLineStyle());
        }

        if (($this->_marker) and ($this->_dataset)) {
            $this->_dataset->_reset();
            $point = $this->_dataset->_next();
            $prevPoint = $this->_dataset->_nearby(-2);
            $nextPoint = $this->_dataset->_nearby();

            $point = $this->_getMarkerData($point, $nextPoint, $prevPoint, $i);
            if (is_array($point)) {
                $point['MARKER_X'] = $x;
                $point['MARKER_Y'] = $y;
                unset ($point['AVERAGE_Y']);
                $this->_marker->_drawMarker($point['MARKER_X'], $point['MARKER_Y'], $point);
            }
        }

        $text = new Image_Graph_Text($x + 20, $y, $this->_title, $font);
        $text->setAlignment(IMAGE_GRAPH_ALIGN_CENTER_Y | IMAGE_GRAPH_ALIGN_LEFT);
        $this->add($text);
        $text->_done();

        return array('Width' => 20+$font->width($this->_title), 'Height' => max(10, $font->height($this->_title)));
    }
Example #21
0
function user_data($user, $num,$shopcoins_class){
	global $timenow, $max, $ysize, $dx, $dy, $im;
	$color[1] = ImageColorAllocate($im, 0, 0, 204);
	$color[2] = ImageColorAllocate($im, 255, 0, 0);
	$color[3] = ImageColorAllocate($im, 0, 204, 102);
	$color[4] = ImageColorAllocate($im, 204, 204, 0);
	$factor = 300/$max;
	$sql = "select FROM_UNIXTIME(date, \"%d.%m.%y\") as d, 
		round((date - ($timenow -86400*31))/ 86400) as number, 
		round($ysize - (host*$factor+$dy)) as rd from ratingbydate 
		where ratinguser=$user and date>".($timenow-86400*31)." and  date<".$timenow."
		order by date;";
	//echo $sql;
	$result = $shopcoins_class->getDataSql($sql);

	foreach ($result as $rows){
		//строим график
		if ($yold)
		{
			ImageLine($im, $xold*12 + $dx, $yold-2, $rows['number']*12 + $dx, $rows['rd']-2, $color[$num]);
			ImageLine($im, $xold*12 + $dx, $yold-1, $rows['number']*12 + $dx, $rows['rd']-1, $color[$num]);
			ImageLine($im, $xold*12 + $dx, $yold, $rows['number']*12 + $dx, $rows['rd'], $color[$num]);
			$xold = $rows['number'];
			$yold = $rows['rd'];
		} else {
			$xold = $rows['number'];
			$yold = $rows['rd'];
		}
//		echo "<br> ---".$rows[0]."---".$rows[1]."---".$rows[2];
	}
	
}
Example #22
0
 public function ImageBorder(&$gdimg, $border_width, $radius_x, $radius_y, $hexcolor_border)
 {
     $border_width = $border_width ? $border_width : 1;
     $radius_x = $radius_x ? $radius_x : 0;
     $radius_y = $radius_y ? $radius_y : 0;
     $output_width = ImageSX($gdimg);
     $output_height = ImageSY($gdimg);
     list($new_width, $new_height) = phpthumb_functions::ProportionalResize($output_width, $output_height, $output_width - max($border_width * 2, $radius_x), $output_height - max($border_width * 2, $radius_y));
     $offset_x = $radius_x ? $output_width - $new_width - $radius_x : 0;
     $offset_y = $radius_y ? $output_height - $new_height - $radius_y : 0;
     //header('Content-Type: image/png');
     //ImagePNG($gdimg);
     //exit;
     if ($gd_border_canvas = phpthumb_functions::ImageCreateFunction($output_width, $output_height)) {
         ImageSaveAlpha($gd_border_canvas, true);
         ImageAlphaBlending($gd_border_canvas, false);
         $color_background = phpthumb_functions::ImageColorAllocateAlphaSafe($gd_border_canvas, 255, 255, 255, 127);
         ImageFilledRectangle($gd_border_canvas, 0, 0, $output_width, $output_height, $color_background);
         $color_border = phpthumb_functions::ImageHexColorAllocate($gd_border_canvas, phpthumb_functions::IsHexColor($hexcolor_border) ? $hexcolor_border : '000000');
         for ($i = 0; $i < $border_width; $i++) {
             ImageLine($gd_border_canvas, floor($offset_x / 2) + $radius_x, $i, $output_width - $radius_x - ceil($offset_x / 2), $i, $color_border);
             // top
             ImageLine($gd_border_canvas, floor($offset_x / 2) + $radius_x, $output_height - 1 - $i, $output_width - $radius_x - ceil($offset_x / 2), $output_height - 1 - $i, $color_border);
             // bottom
             ImageLine($gd_border_canvas, floor($offset_x / 2) + $i, $radius_y, floor($offset_x / 2) + $i, $output_height - $radius_y, $color_border);
             // left
             ImageLine($gd_border_canvas, $output_width - 1 - $i - ceil($offset_x / 2), $radius_y, $output_width - 1 - $i - ceil($offset_x / 2), $output_height - $radius_y, $color_border);
             // right
         }
         if ($radius_x && $radius_y) {
             // PHP bug: ImageArc() with thicknesses > 1 give bad/undesirable/unpredicatable results
             // Solution: Draw multiple 1px arcs side-by-side.
             // Problem: parallel arcs give strange/ugly antialiasing problems
             // Solution: draw non-parallel arcs, from one side of the line thickness at the start angle
             //   to the opposite edge of the line thickness at the terminating angle
             for ($thickness_offset = 0; $thickness_offset < $border_width; $thickness_offset++) {
                 ImageArc($gd_border_canvas, floor($offset_x / 2) + 1 + $radius_x, $thickness_offset - 1 + $radius_y, $radius_x * 2, $radius_y * 2, 180, 270, $color_border);
                 // top-left
                 ImageArc($gd_border_canvas, $output_width - $radius_x - 1 - ceil($offset_x / 2), $thickness_offset - 1 + $radius_y, $radius_x * 2, $radius_y * 2, 270, 360, $color_border);
                 // top-right
                 ImageArc($gd_border_canvas, $output_width - $radius_x - 1 - ceil($offset_x / 2), $output_height - $thickness_offset - $radius_y, $radius_x * 2, $radius_y * 2, 0, 90, $color_border);
                 // bottom-right
                 ImageArc($gd_border_canvas, floor($offset_x / 2) + 1 + $radius_x, $output_height - $thickness_offset - $radius_y, $radius_x * 2, $radius_y * 2, 90, 180, $color_border);
                 // bottom-left
             }
             if ($border_width > 1) {
                 for ($thickness_offset = 0; $thickness_offset < $border_width; $thickness_offset++) {
                     ImageArc($gd_border_canvas, floor($offset_x / 2) + $thickness_offset + $radius_x, $radius_y, $radius_x * 2, $radius_y * 2, 180, 270, $color_border);
                     // top-left
                     ImageArc($gd_border_canvas, $output_width - $thickness_offset - $radius_x - 1 - ceil($offset_x / 2), $radius_y, $radius_x * 2, $radius_y * 2, 270, 360, $color_border);
                     // top-right
                     ImageArc($gd_border_canvas, $output_width - $thickness_offset - $radius_x - 1 - ceil($offset_x / 2), $output_height - $radius_y, $radius_x * 2, $radius_y * 2, 0, 90, $color_border);
                     // bottom-right
                     ImageArc($gd_border_canvas, floor($offset_x / 2) + $thickness_offset + $radius_x, $output_height - $radius_y, $radius_x * 2, $radius_y * 2, 90, 180, $color_border);
                     // bottom-left
                 }
             }
         }
         $this->phpThumbObject->ImageResizeFunction($gd_border_canvas, $gdimg, floor(($output_width - $new_width) / 2), round(($output_height - $new_height) / 2), 0, 0, $new_width, $new_height, $output_width, $output_height);
         ImageDestroy($gdimg);
         $gdimg = phpthumb_functions::ImageCreateFunction($output_width, $output_height);
         ImageSaveAlpha($gdimg, true);
         ImageAlphaBlending($gdimg, false);
         $gdimg_color_background = phpthumb_functions::ImageColorAllocateAlphaSafe($gdimg, 255, 255, 255, 127);
         ImageFilledRectangle($gdimg, 0, 0, $output_width, $output_height, $gdimg_color_background);
         ImageCopy($gdimg, $gd_border_canvas, 0, 0, 0, 0, $output_width, $output_height);
         //$gdimg = $gd_border_canvas;
         ImageDestroy($gd_border_canvas);
         return true;
     } else {
         $this->DebugMessage('FAILED: $gd_border_canvas = phpthumb_functions::ImageCreateFunction(' . $output_width . ', ' . $output_height . ')', __FILE__, __LINE__);
     }
     return false;
 }
Example #23
0
// create a true color image (requires GD2)
$image = ImageCreateTrueColor(400, 300);
ImageAlphaBlending($image, true);
// allocate some colors
$black = ImageColorAllocate($image, 0, 0, 0);
$red = ImageColorAllocate($image, 0xff, 0, 0);
$green = ImageColorAllocate($image, 0, 0xff, 0);
$blue = ImageColorAllocate($image, 0, 0, 0xff);
$white = ImageColorAllocate($image, 0xff, 0xff, 0xff);
// create a frame
ImageFilledRectangle($image, 0, 0, 399, 299, $white);
ImageRectangle($image, 0, 0, 399, 299, $black);
// draw some lines
ImageLine($image, 200, 50, 350, 150, $red);
ImageLine($image, 200, 60, 350, 160, $green);
ImageLine($image, 200, 70, 350, 170, $blue);
// draw some overlapping alpha blended boxes
$redAlpha = ImageColorAllocateAlpha($image, 0xff, 0, 0, 75);
$blueAlpha = ImageColorAllocateAlpha($image, 0, 0xff, 0, 75);
$greenAlpha = ImageColorAllocateAlpha($image, 0, 0, 0xff, 75);
ImageFilledRectangle($image, 50, 50, 90, 90, $redAlpha);
ImageFilledRectangle($image, 60, 80, 100, 120, $greenAlpha);
ImageFilledRectangle($image, 80, 60, 120, 100, $blueAlpha);
// write some _default_ text
for ($font = 1; $font <= 5; $font++) {
    ImageString($image, $font, 50, 150 + $font * 20, 'Testing GD output', $black);
}
ImageString($image, 3, 51, 21, 'Congratulations! The GD2 installation works', $black);
ImageString($image, 3, 50, 20, 'Congratulations! The GD2 installation works', $red);
// output the test image
header('Content-Type: image/png');
Example #24
0
function Graf($arrayX, $arrayY, $ImageHandle, $MinX, $MaxX, $MinY, $MaxY, $Color = 'FF0000', $dashed = "N", $thikness = 2, $antialiase = true)
{
    global $xA, $yA, $xPixelLength, $yPixelLength;
    if (sizeof($arrayX) != sizeof($arrayY)) {
        return;
    }
    $arr_Color = ReColor($Color);
    $color = ImageColorAllocate($ImageHandle, $arr_Color[0], $arr_Color[1], $arr_Color[2]);
    $xGrafLength = $MaxX - $MinX;
    $yGrafLength = $MaxY - $MinY;
    if ($antialiase) {
        $bgcolor = imagecolorallocate($ImageHandle, 255, 255, 255);
        $fgcolors = imagecolorsforindex($ImageHandle, $color);
        $bgcolors = imagecolorsforindex($ImageHandle, $bgcolor);
        for ($i = 0; $i < 100; $i++) {
            imagecolorallocate($ImageHandle, ($fgcolors['red'] + $i * $bgcolors['red']) / ($i + 1), ($fgcolors['green'] + $i * $bgcolors['green']) / ($i + 1), ($fgcolors['blue'] + $i * $bgcolors['blue']) / ($i + 1));
        }
    }
    $x1 = $y1 = $x2 = $y2 = 0;
    for ($i = 0, $n = sizeof($arrayX) - 1; $i < $n; $i++) {
        if ($xGrafLength > 0) {
            $x1 = $xA + ($arrayX[$i] - $MinX) * $xPixelLength / $xGrafLength;
            $x2 = $xA + ($arrayX[$i + 1] - $MinX) * $xPixelLength / $xGrafLength;
        }
        if ($yGrafLength > 0) {
            $y1 = $yA - ($arrayY[$i] - $MinY) * $yPixelLength / $yGrafLength;
            $y2 = $yA - ($arrayY[$i + 1] - $MinY) * $yPixelLength / $yGrafLength;
        }
        $x1 = ceil($x1);
        $y1 = ceil($y1);
        $x2 = ceil($x2);
        $y2 = ceil($y2);
        if ($antialiase) {
            /** @noinspection PhpUndefinedVariableInspection */
            _a_draw_line($ImageHandle, $x1, $y1, $x2, $y2, $fgcolors, $dashed, 10, 4);
            if ($thikness > 1) {
                if ($y1 < $y2) {
                    _a_draw_line($ImageHandle, $x1 - 0.4, $y1 + 0.4, $x2 - 0.4, $y2 + 0.4, $fgcolors, $dashed, 10, 4);
                    _a_draw_line($ImageHandle, $x1 + 0.4, $y1 - 0.4, $x2 + 0.4, $y2 - 0.4, $fgcolors, $dashed, 10, 4);
                } else {
                    _a_draw_line($ImageHandle, $x1 + 0.4, $y1 + 0.4, $x2 + 0.4, $y2 + 0.4, $fgcolors, $dashed, 10, 4);
                    _a_draw_line($ImageHandle, $x1 - 0.4, $y1 - 0.4, $x2 - 0.4, $y2 - 0.4, $fgcolors, $dashed, 10, 4);
                }
            }
        } elseif ($dashed == "Y") {
            $style = array($color, $color, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT, IMG_COLOR_TRANSPARENT);
            ImageSetStyle($ImageHandle, $style);
            ImageLine($ImageHandle, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);
        } else {
            ImageLine($ImageHandle, $x1, $y1, $x2, $y2, $color);
        }
    }
}
 function DrawDashedLine($x1pix, $y1pix, $x2pix, $y2pix, $dash_length, $dash_space, $color)
 {
     //Code based on work by Ariel Garza and James Pine
     //I've decided to have this be in pixels only as a replacement for ImageLine
     //$x1pix = $this->xtr($x1);
     //$y1pix = $this->ytr($y1);
     //$x2pix = $this->xtr($x2);
     //$y2pix = $this->ytr($y2);
     // Get the length of the line in pixels
     $line_length = ceil(sqrt(pow($x2pix - $x1pix, 2) + pow($y2pix - $y1pix, 2)));
     $dx = ($x2pix - $x1pix) / $line_length;
     $dy = ($y2pix - $y1pix) / $line_length;
     $lastx = $x1pix;
     $lasty = $y1pix;
     // Draw the dashed line
     for ($i = 0; $i < $line_length; $i += $dash_length + $dash_space) {
         $xpix = $dash_length * $dx + $lastx;
         $ypix = $dash_length * $dy + $lasty;
         ImageLine($this->img, $lastx, $lasty, $xpix, $ypix, $color);
         $lastx = $xpix + $dash_space * $dx;
         $lasty = $ypix + $dash_space * $dy;
     }
 }
Example #26
0
 function DrawPie()
 {
     $width = $this->chart_area[2] - $this->chart_area[0];
     $height = $this->chart_area[3] - $this->chart_area[1];
     list($r, $g, $b) = ColorSet('black');
     $black = ImageColorAllocate($this->img, $r, $g, $b);
     $xpos = $this->chart_area[0] + $width / 2;
     $ypos = $this->chart_area[1] + $height / 2;
     $durchmesser = min($width, $height) * 0.97;
     $radius = $durchmesser / 2;
     ImageArc($this->img, $xpos, $ypos, $durchmesser, $durchmesser, 0, 360, $black);
     //ImageFillToBorder($this->img, $xpos, $ypos, $black, $black);
     $helpcol = ImageColorAllocate($this->img, 12, 12, 12);
     ImageArc($this->img, $xpos, $ypos, $durchmesser, $durchmesser, 0, 360, $helpcol);
     $i = 0;
     $total = 0;
     foreach ($this->data_values as $row) {
         $colcount = 0;
         $i = 0;
         foreach ($row as $v) {
             if ($v != $row[0]) {
                 // sum up
                 $sumarr[$i] += $v;
                 $total += $v;
             }
             $i++;
         }
     }
     $colcount = 0;
     $kreis_start = $this->arc_start;
     $umfang = $radius * 2 * pi();
     $winkel = $kreis_start;
     foreach ($sumarr as $val) {
         if ($colcount >= count($this->bar_color)) {
             $colcount = 0;
         }
         $prozent = number_format($val / $total * 100, 1, ',', '.') . '%';
         $val = round($val / $total * 360);
         $winkel += $val;
         $farbwinkel = $winkel - $val / 2;
         $val += $kreis_start;
         $barcol = $this->bar_color[$colcount];
         list($r, $g, $b) = ColorSet($barcol);
         $barcol = ImageColorAllocate($this->img, $r, $g, $b);
         //ImageArc($this->img, $xpos, $ypos, $durchmesser, $durchmesser, $kreis_start, $val, $black);
         ImageArc($this->img, $xpos, $ypos, $durchmesser, $durchmesser, 0, 3560, $black);
         $out_x = $radius * cos(deg2rad($winkel));
         $out_y = -$radius * sin(deg2rad($winkel));
         $halbradius = $radius / 2;
         $farb_x = $xpos + $halbradius * cos(deg2rad($farbwinkel));
         $farb_y = $ypos + -$halbradius * sin(deg2rad($farbwinkel));
         $out_x = $xpos + $out_x;
         $out_y = $ypos + $out_y;
         ImageLine($this->img, $xpos, $ypos, $out_x, $out_y, $black);
         //ImageLine($this->img, $xpos, $ypos, $farb_x, $farb_y, $black);
         ImageFillToBorder($this->img, $farb_x, $farb_y, $black, $barcol);
         ImageTTFText($this->img, $this->axis_font_size, 0, $farb_x, $farb_y, $black, $this->font, $prozent);
         $kreis_start = $val;
         $colcount++;
     }
     //ImageArc($this->img, $xpos, $ypos, $durchmesser, $durchmesser, 0, 360, $black);
 }
Example #27
0
File: image.php Project: haojue/STB
<?php

$height = 300;
$width = 300;
$im = ImageCreateTrueColor($width, $height);
$white = ImageColorAllocate($im, 255, 255, 255);
$blue = ImageColorAllocate($im, 0, 0, 64);
ImageFill($im, 0, 0, $blue);
ImageLine($im, 0, 0, $width, $height, $white);
ImageString($im, 4, 80, 150, PHP, $white);
Header("Content-type: image/png");
ImagePng($im);
ImageDestroy($im);
Example #28
0
 function DrawSquared()
 {
     // This will tell us if lines have already begun to be drawn.
     // It is an array to keep separate information for every line, for with a single
     // variable we could sometimes get "undefined offset" errors and no plot...
     $start_lines = array_fill(0, $this->records_per_group, FALSE);
     if ($this->data_type == 'text-data') {
         $lastx[0] = $this->xtr(0);
         $lasty[0] = $this->xtr(0);
     }
     for ($row = 0, $cnt = 0; $row < $this->num_data_rows; $row++) {
         $record = 1;
         // Skip record #0 (data label)
         if ($this->data_type == 'data-data') {
             // Do we have a value for X?
             $x_now = $this->data[$row][$record++];
         } else {
             $x_now = 0.5 + $cnt++;
         }
         // Place text-data at X = 0.5, 1.5, 2.5, etc...
         $x_now_pixels = $this->xtr($x_now);
         // Absolute coordinates
         if ($this->x_data_label_pos != 'none') {
             // Draw X Data labels?
             $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels);
         }
         // notice there is no last param.
         // Draw Lines
         for ($idx = 0; $record < $this->num_recs[$row]; $record++, $idx++) {
             if (is_numeric($this->data[$row][$record])) {
                 // Allow for missing Y data
                 $y_now_pixels = $this->ytr($this->data[$row][$record]);
                 if ($start_lines[$idx] == TRUE) {
                     // Set line width, revert it to normal at the end
                     ImageSetThickness($this->img, $this->line_widths[$idx]);
                     if ($this->line_styles[$idx] == 'dashed') {
                         $this->SetDashedStyle($this->ndx_data_colors[$idx]);
                         ImageLine($this->img, $lastx[$idx], $lasty[$idx], $x_now_pixels, $lasty[$idx], IMG_COLOR_STYLED);
                         ImageLine($this->img, $x_now_pixels, $lasty[$idx], $x_now_pixels, $y_now_pixels, IMG_COLOR_STYLED);
                     } else {
                         ImageLine($this->img, $lastx[$idx], $lasty[$idx], $x_now_pixels, $lasty[$idx], $this->ndx_data_colors[$idx]);
                         ImageLine($this->img, $x_now_pixels, $lasty[$idx], $x_now_pixels, $y_now_pixels, $this->ndx_data_colors[$idx]);
                     }
                 }
                 $lastx[$idx] = $x_now_pixels;
                 $lasty[$idx] = $y_now_pixels;
                 $start_lines[$idx] = TRUE;
             } elseif ($this->draw_broken_lines) {
                 $start_lines[$idx] = FALSE;
             }
         }
     }
     // end while
     ImageSetThickness($this->img, 1);
     return TRUE;
 }
Example #29
0
 function DrawDashedLine($x1, $y1, $x2, $y2, $dash_length, $dash_space, $color)
 {
     if ($dash_length) {
         $dashes = array_fill(0, $dash_length, $color);
     } else {
         $dashes = array();
     }
     if ($dash_space) {
         $spaces = array_fill(0, $dash_space, IMG_COLOR_TRANSPARENT);
     } else {
         $spaces = array();
     }
     $style = array_merge($dashes, $spaces);
     ImageSetStyle($this->img, $style);
     ImageLine($this->img, $x1, $y1, $x2, $y2, IMG_COLOR_STYLED);
 }
Example #30
0
 protected function DrawSquared()
 {
     if (!$this->CheckDataType('text-data, data-data')) {
         return FALSE;
     }
     // Flag array telling if the current point is valid, one element per plot line.
     // If start_lines[i] is true, then (lastx[i], lasty[i]) is the previous point.
     $start_lines = array_fill(0, $this->records_per_group, FALSE);
     for ($row = 0, $cnt = 0; $row < $this->num_data_rows; $row++) {
         $record = 1;
         // Skip record #0 (data label)
         if ($this->data_type == 'data-data') {
             // Do we have a value for X?
             $x_now = $this->data[$row][$record++];
         } else {
             $x_now = 0.5 + $cnt++;
         }
         // Place text-data at X = 0.5, 1.5, 2.5, etc...
         $x_now_pixels = $this->xtr($x_now);
         // Absolute coordinates
         if ($this->x_data_label_pos != 'none') {
             // Draw X Data labels?
             $this->DrawXDataLabel($this->data[$row][0], $x_now_pixels);
         }
         // notice there is no last param.
         // Draw Lines
         for ($idx = 0; $record < $this->num_recs[$row]; $record++, $idx++) {
             if (is_numeric($this->data[$row][$record])) {
                 // Allow for missing Y data
                 $y_now_pixels = $this->ytr($this->data[$row][$record]);
                 if ($start_lines[$idx] == TRUE) {
                     // Set line width, revert it to normal at the end
                     ImageSetThickness($this->img, $this->line_widths[$idx]);
                     if ($this->line_styles[$idx] == 'dashed') {
                         $this->SetDashedStyle($this->ndx_data_colors[$idx]);
                         ImageLine($this->img, $lastx[$idx], $lasty[$idx], $x_now_pixels, $lasty[$idx], IMG_COLOR_STYLED);
                         ImageLine($this->img, $x_now_pixels, $lasty[$idx], $x_now_pixels, $y_now_pixels, IMG_COLOR_STYLED);
                     } else {
                         ImageLine($this->img, $lastx[$idx], $lasty[$idx], $x_now_pixels, $lasty[$idx], $this->ndx_data_colors[$idx]);
                         ImageLine($this->img, $x_now_pixels, $lasty[$idx], $x_now_pixels, $y_now_pixels, $this->ndx_data_colors[$idx]);
                     }
                 }
                 $lastx[$idx] = $x_now_pixels;
                 $lasty[$idx] = $y_now_pixels;
                 $start_lines[$idx] = TRUE;
             } else {
                 if ($this->draw_broken_lines) {
                     $start_lines[$idx] = FALSE;
                 }
             }
         }
     }
     // end while
     ImageSetThickness($this->img, 1);
     return TRUE;
 }