Пример #1
0
 public function getPNG()
 {
     // создаем картинку
     $image = imageCreate($this->width + $this->widthLegend, $this->height);
     $backColor = imageColorAllocate($image, $this->colorBG >> 16, ($this->colorBG >> 8) % 256, $this->colorBG % 256);
     $centerColor = imageColorAllocate($image, $this->colorCenter >> 16, ($this->colorCenter >> 8) % 256, $this->colorCenter % 256);
     $pointsColor = imageColorAllocate($image, $this->colorPoints >> 16, ($this->colorPoints >> 8) % 256, $this->colorPoints % 256);
     $legendColor = imageColorAllocate($image, $this->colorLegend >> 16, ($this->colorLegend >> 8) % 256, $this->colorLegend % 256);
     // background
     imageFilledRectangle($image, 0, 0, $this->width, $this->height, $backColor);
     imageRectangle($image, $this->width, 0, $this->widthLegend + $this->width - 1, $this->height - 1, $legendColor);
     // добавляем масштаб в легенду
     imageLine($image, $this->width + 10, $this->height - $this->fontSize * 2 - 1, $this->width + 10, $this->height - $this->fontSize * 2 + 1, $legendColor);
     imageLine($image, $this->width + 10, $this->height - $this->fontSize * 2, $this->width + 20, $this->height - $this->fontSize * 2, $legendColor);
     imageLine($image, $this->width + 20, $this->height - $this->fontSize * 2 - 1, $this->width + 20, $this->height - $this->fontSize * 2 + 1, $legendColor);
     imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize + 20, $this->height - $this->fontSize * 1.5, $legendColor, $this->pathToFont, "{$this->metersIn10Pix} {$this->metersLabel}");
     // center
     imageFilledEllipse($image, $this->centerWidth, $this->centerHeight, $this->sizePoints, $this->sizePoints, $centerColor);
     imageTTFText($image, $this->fontSize, 0, $this->centerWidth, $this->centerHeight + $this->fontSize + $this->sizePoints, $centerColor, $this->pathToFont, "0");
     imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize, $this->fontSize * 2, $legendColor, $this->pathToFont, "0 - {$this->centerLabel}");
     // points
     $i = 1;
     foreach ($this->pointsBased as $v) {
         $angle = $v->getPoint()->getAzimuth() - 90;
         // угол для тригонометрии
         $pointWidth = $this->centerWidth + $this->k * ($v->getPoint()->getDistance() * cos(deg2rad($angle)));
         $pointHeight = $this->centerHeight + $this->k * ($v->getPoint()->getDistance() * sin(deg2rad($angle)));
         // рисуем точку
         imageEllipse($image, $pointWidth, $pointHeight, $this->sizePoints, $this->sizePoints, $pointsColor);
         // подпись
         imageTTFText($image, $this->fontSize, 0, $pointWidth, $pointHeight + $this->fontSize + $this->sizePoints, $pointsColor, $this->pathToFont, $i);
         // в легенду
         imageTTFText($image, $this->fontSize, 0, $this->width + $this->fontSize, $this->fontSize * 2 * ($i + 1), $legendColor, $this->pathToFont, "{$i} - " . $v->getTitle());
         $i++;
     }
     ob_start();
     imagePng($image);
     $str = ob_get_clean();
     return $str;
 }
Пример #2
0
 /**
  * Function: drawActor
  *
  * Draws then given cloud.
  */
 function drawActor($x, $y, $w, $h, $fill = null, $stroke = null, $shadow = false)
 {
     if (isset($fill)) {
         if ($shadow) {
             $dx = mxConstants::$SHADOW_OFFSETX;
             $dy = mxConstants::$SHADOW_OFFSETY;
             imageFilledEllipse($this->image, $x + 0.5 * $w + $dx, $y + 0.2 * $h + $dy, 0.4 * $w, 0.4 * $h, $this->shadowColor);
             imageFilledEllipse($this->image, $x + 0.2 * $w + $dx, $y + 0.6 * $h + $dy, 0.4 * $w, 0.4 * $h, $this->shadowColor);
             imageFilledEllipse($this->image, $x + 0.8 * $w + $dx, $y + 0.6 * $h + $dy, 0.4 * $w, 0.4 * $h, $this->shadowColor);
             imageFilledRectangle($this->image, $x + 0.2 * $w + $dx, $y + 0.4 * $h + $dy, $x + 0.8 * $w + $dx, $y + 0.6 * $h + $dy, $this->shadowColor);
             imageFilledRectangle($this->image, $x + $dx, $y + 0.6 * $h + $dy, $x + $w + $dx, $y + $h + $dy, $this->shadowColor);
         }
         $fill = $this->getColor($fill);
         imageFilledEllipse($this->image, $x + 0.5 * $w, $y + 0.2 * $h, 0.4 * $w, 0.4 * $h, $fill);
         imageFilledEllipse($this->image, $x + 0.2 * $w, $y + 0.6 * $h, 0.4 * $w, 0.4 * $h, $fill);
         imageFilledEllipse($this->image, $x + 0.8 * $w, $y + 0.6 * $h, 0.4 * $w, 0.4 * $h, $fill);
         imageFilledRectangle($this->image, $x + 0.2 * $w, $y + 0.4 * $h, $x + 0.8 * $w, $y + 0.6 * $h, $fill);
         imageFilledRectangle($this->image, $x, $y + 0.6 * $h, $x + $w, $y + $h, $fill);
     }
     if ($stroke != null) {
         $stroke = $this->getColor($stroke);
         imageEllipse($this->image, $x + 0.5 * $w, $y + 0.2 * $h, 0.4 * $w, 0.4 * $h, $stroke);
         imageLine($this->image, $x + 0.2 * $w, $y + 0.4 * $h, $x + 0.8 * $w, $y + 0.4 * $h, $stroke);
         imageArc($this->image, $x + 0.2 * $w, $y + 0.6 * $h, 0.4 * $w, 0.4 * $h, 180, 270, $stroke);
         imageArc($this->image, $x + 0.8 * $w, $y + 0.6 * $h, 0.4 * $w, 0.4 * $h, 270, 360, $stroke);
         imageLine($this->image, $x, $y + 0.6 * $h, $x, $y + $h, $stroke);
         imageLine($this->image, $x, $y + $h, $x + $w, $y + $h, $stroke);
         imageLine($this->image, $x + $w, $y + $h, $x + $w, $y + 0.6 * $h, $stroke);
     }
 }
Пример #3
0
 /**
  * Fills a ellipse on the image
  * @param Point $center Point of the ellipse center
  * @param Dimension $dimension Dimension of the ellipse
  * @param Color $color
  * @return null
  */
 public function fillEllipse(Point $center, Dimension $dimension, Color $color)
 {
     $color = $this->allocateColor($color);
     $x = $center->getX();
     $y = $center->getY();
     $width = $dimension->getWidth();
     $height = $dimension->getHeight();
     imageFilledEllipse($this->resource, $x, $y, $width, $height, $color);
 }
Пример #4
0
} else {
    $width = imageFontWidth(5);
    $height = imageFontHeight(5);
    if ($x + (strlen($user) + 1) * $width > 500) {
        $stringx = $x - (strlen($user) + 1) * $width - 12;
    }
    if ($y + $height > 500) {
        $stringy = $y - $height / 2 - 2;
    }
    $magenta = imageColorAllocate($map, 255, 0, 255);
    imageColorTransparent($map, $magenta);
    $brown = imagecolorallocate($map, 102, 51, 0);
    $parchment = imagecolorallocate($map, 255, 255, 204);
    // Avoid drawing a brown dot on a brown area
    $rgb = imageColorAt($map, $x, $y);
    if ($rgb > 0) {
        // $rgb is 0 on our parchment-colored areas
        $temp = $brown;
        $brown = $parchment;
        $parchment = $temp;
    }
    // YOU ARE HERE
    imageFilledEllipse($map, $x, $y, 6, 6, $brown);
    // background for text
    imageFilledRectangle($map, $stringx + 6, $stringy - $height / 2, $stringx + 6 + $width * (strlen($user) + 1), $stringy + $height / 2, $brown);
    // text itself
    imageString($map, 5, $stringx + 7 + $width / 2, $stringy - $height / 2 - 1, $user, $parchment);
}
header("Content-type: image/png");
imagePNG($map);
imageDestroy($map);
Пример #5
0
<?php

include "config.php";
$file = fopen($irpg_db, "r");
fgets($file);
session_start();
// sessions to generate only one map / person / 20s
if (isset($_SESSION['time']) && time() - $_SESSION['time'] < 20) {
    header("Location: maperror.png");
    exit(0);
}
$_SESSION['time'] = time();
$map = imageCreate(500, 500);
$magenta = ImageColorAllocate($map, 255, 0, 255);
$blue = imageColorAllocate($map, 0, 128, 255);
$red = imageColorAllocate($map, 211, 0, 0);
ImageColorTransparent($map, $magenta);
while ($line = fgets($file)) {
    list(, , , , , , , , $online, , $x, $y) = explode("\t", trim($line));
    if ($online == 1) {
        imageFilledEllipse($map, $x, $y, 3, 3, $blue);
    } else {
        imageFilledEllipse($map, $x, $y, 3, 3, $red);
    }
}
header("Content-type: image/png");
imagePNG($map);
imageDestroy($map);
Пример #6
0
            $player[3]['y'] = $arg[3];
        }
    } elseif ($arg[0] == "P4") {
        $player[4]['name'] = $arg[1];
        if ($type == 2) {
            $player[4]['x'] = $arg[2];
            $player[4]['y'] = $arg[3];
        }
    }
}
if ($type != 2) {
    header("Location: maperror.png");
    exit(0);
}
$map = imageCreate(500, 500);
$magenta = imageColorAllocate($map, 255, 0, 255);
imageColorTransparent($map, $magenta);
$blue = imageColorAllocate($map, 0, 128, 255);
$red = imageColorAllocate($map, 255, 0, 0);
imageFilledEllipse($map, $player[1]['x'], $player[1]['y'], 6, 6, $blue);
imageFilledEllipse($map, $player[2]['x'], $player[2]['y'], 6, 6, $blue);
imageFilledEllipse($map, $player[3]['x'], $player[3]['y'], 6, 6, $blue);
imageFilledEllipse($map, $player[4]['x'], $player[4]['y'], 6, 6, $blue);
if ($stage == 1) {
    imageFilledEllipse($map, $p1[0], $p1[1], 8, 8, $red);
} else {
    imageFilledEllipse($map, $p2[0], $p2[1], 9, 9, $red);
}
header("Content-type: image/png");
imagePNG($map);
imageDestroy($map);
Пример #7
0
    $b = rand($img_rgb_min, $img_rgb_max);
    $bg = imageColorAllocate($img, $r, $g, $b);
    imageFill($img, 0, 0, $bg);
}
// Circles
if ($img_use_circles) {
    for ($i = 1; $i <= $img_circles; $i++) {
        $cx = rand(0, $img_width - 10);
        $cy = rand(0, $img_height - 3);
        $w = rand(20, 70);
        $h = rand(20, 70);
        $r = rand($img_rgb_min, $img_rgb_max);
        $g = rand($img_rgb_min, $img_rgb_max);
        $b = rand($img_rgb_min, $img_rgb_max);
        $color = imageColorAllocate($img, $r, $g, $b);
        imageFilledEllipse($img, $cx, $cy, $w, $h, $color);
    }
}
// Grid
if ($img_use_grid) {
    $xline = 0;
    $yline = 0;
    $grid_spacing = b1n_arrayRand($img_grid_spacing_values);
    $grid_x_inc = round($img_width / $grid_spacing);
    $grid_y_inc = round($img_height / $grid_spacing);
    // X Axis
    for ($x = 0; $x < $grid_x_inc; $x++) {
        if ($img_grid_random_color) {
            $r = rand($txt_rgb_min, $txt_rgb_max);
            $g = rand($txt_rgb_min, $txt_rgb_max);
            $b = rand($txt_rgb_min, $txt_rgb_max);
Пример #8
0
<?php

## Работа с полупрозрачными цветами.
$size = 300;
$im = imageCreateTrueColor($size, $size);
$back = imageColorAllocate($im, 255, 255, 255);
imageFilledRectangle($im, 0, 0, $size - 1, $size - 1, $back);
// Создаем идентификаторы полупрозрачных цветов.
$yellow = imageColorAllocateAlpha($im, 255, 255, 0, 75);
$red = imageColorAllocateAlpha($im, 255, 0, 0, 75);
$blue = imageColorAllocateAlpha($im, 0, 0, 255, 75);
// Рисуем 3 пересекающихся круга.
$radius = 150;
imageFilledEllipse($im, 100, 75, $radius, $radius, $yellow);
imageFilledEllipse($im, 120, 165, $radius, $radius, $red);
imageFilledEllipse($im, 187, 125, $radius, $radius, $blue);
// Выводим изображение в браузер.
header('Content-type: image/png');
imagePng($im);
 /**
  * Creates and outputs the final image. 
  */
 protected function createImage()
 {
     // calculate image width
     foreach ($this->charWidth as $width) {
         $this->captchaWidth += $width;
     }
     if ($this->captchaWidth + strlen($this->codeWord) * 10 <= 300) {
         $this->captchaWidth = 300;
     }
     // create final image
     $captcha = imageCreate($this->captchaWidth + 40, $this->captchaHeight);
     $min = 0;
     // insert background
     if (CAPTCHA_RANDOM_BACKGROUND) {
         for ($y = 1; $y <= $this->elements; $y++) {
             $size = $elementsArr[$y]['size'] = mt_rand(150, 250);
             $elementsArr[$y]['pos'] = array(mt_rand($min, $min + $size), mt_rand(20, 80));
             $min = $min + $size + 50;
         }
         $tempRed = $this->color2['red'];
         $tempYellow = $this->color2['green'];
         $tempBlue = $this->color2['blue'];
         $counter = 0;
         for ($x = $this->gradientBorder; $x > 0; $x--) {
             if ($tempRed != $this->color1['red']) {
                 if ($this->gradient['red']['direction'] == 'up') {
                     $tempRed++;
                 } else {
                     $tempRed--;
                 }
             }
             if ($tempYellow != $this->color1['green']) {
                 if ($this->gradient['green']['direction'] == 'up') {
                     $tempYellow++;
                 } else {
                     $tempYellow--;
                 }
             }
             if ($tempBlue != $this->color1['blue']) {
                 if ($this->gradient['blue']['direction'] == 'up') {
                     $tempBlue++;
                 } else {
                     $tempBlue--;
                 }
             }
             $color = imageColorAllocate($captcha, $tempRed, $tempYellow, $tempBlue);
             foreach ($elementsArr as $element) {
                 imageFilledEllipse($captcha, $element['pos'][0], $element['pos'][1], $element['size'] - $counter, $element['size'] - $counter, $color);
             }
             $counter++;
         }
     } else {
         $tempColor = imageColorAllocate($captcha, 255, 255, 255);
     }
     // insert character images
     $counter = $y = 0;
     foreach ($this->chars as $char) {
         imageCopy($captcha, $char, $y, mt_rand(0, 30), 0, 0, $this->charWidth[$counter], $this->captchaHeight);
         imageDestroy($char);
         $y = $y + $this->charWidth[$counter] + mt_rand(0, 10);
         $counter++;
     }
     // insert random lines
     if (CAPTCHA_RANDOM_LINES) {
         for ($x = 1; $x <= $this->lines; $x++) {
             imageSetThickness($captcha, mt_rand(1, 3));
             $pos1 = array('x' => mt_rand(2, $this->captchaWidth - 2), 'y' => mt_rand(2, $this->captchaHeight - 2));
             $pos2 = array('x' => mt_rand(2, $this->captchaWidth - 2), 'y' => mt_rand(2, $this->captchaHeight - 2));
             $lineColor = imageColorAllocate($captcha, $this->fontColor['red'], $this->fontColor['green'], $this->fontColor['blue']);
             imageLine($captcha, $pos1['x'], $pos1['y'], $pos2['x'], $pos2['y'], $lineColor);
         }
     }
     // output image
     imagePng($captcha);
     // destroy image
     imageDestroy($captcha);
 }