/**
  * draw point on map
  *
  * @param Map $map
  */
 public function draw(Map $map)
 {
     parent::draw($map);
     $point = $map->getPixelPointFromCoordinates($this->getLon(), $this->getLat());
     $vertices = array($point['x'], $point['y'], $point['x'] - 10, $point['y'] - 20, $point['x'] + 10, $point['y'] - 20);
     imagefilledpolygon($map->getImage(), $vertices, 3, imagecolorallocate($map->getImage(), 200, 0, 0));
 }
 function CreatePolygon($strconn, $schema, $table, $column, $srid, $largo, $ancho, $r, $g, $b, $trans, $zoom, $despX, $despY)
 {
     $conn = pg_connect($strconn) or die("Error de Conexion con la base de datos");
     $imagen = imagecreatetruecolor($largo, $ancho);
     $transparencia = imagecolorallocatealpha($imagen, 0, 0, 0, 127);
     imagefilltoborder($imagen, 50, 50, $transparencia, $transparencia);
     imagesavealpha($imagen, true);
     $color = imagecolorallocatealpha($imagen, $r, $g, $b, $trans);
     $query = "\n        SELECT gid, ((geometria.x - medidas.xinicial)/medidas.factor) x, ({$ancho} - ((geometria.y - medidas.yinicial)/medidas.factor)) y \n        FROM \n           (SELECT gid, st_x((ST_DumpPoints(geom)).geom) x, st_y((ST_DumpPoints(geom)).geom) y \n            FROM \n               (SELECT gid, tab.{$column} geom FROM {$schema}.\"{$table}\" tab\n                WHERE st_intersects(\n                        (SELECT st_setsrid(Box2D(st_buffer(p.centroide,((375336.1936-(375336.1936 * {$zoom} ))/2))), {$srid}) geom FROM \n                            (SELECT ST_GeomFROMText(st_astext(st_point( 470971.458311897-((470971.458311897 * {$despX} )/2) , 1072807.08034292-((470971.458311897 * {$despY} )/2) )), {$srid}) centroide) p\n                        ), tab.{$column})\n                ) s \n           ) geometria,\n           (SELECT min(st_xmin(geom)) xinicial, (max(st_xmax(geom))-min(st_xmin(geom)))/{$ancho} factor,min(st_ymin(geom)) yinicial \n            FROM \n               (SELECT st_setsrid(Box2D(st_buffer(p.centroide,((375336.1936-(375336.1936 * {$zoom} ))/2))), {$srid}) geom FROM \n                    (SELECT ST_GeomFROMText(st_astext(st_point( 470971.458311897-((470971.458311897 * {$despX} )/2) , 1072807.08034292-((470971.458311897 * {$despY} )/2) )), {$srid}) centroide) p\n               ) c \n           ) medidas";
     $result = pg_query($conn, $query) or die("Error al ejecutar la consulta");
     $gid = '';
     $pointPolygonArray = array();
     while ($row = pg_fetch_row($result)) {
         if ($gid == '') {
             $gid = $row[0];
             array_push($pointPolygonArray, $row[1], $row[2]);
         } else {
             if ($gid == $row[0]) {
                 array_push($pointPolygonArray, $row[1], $row[2]);
             } else {
                 imagefilledpolygon($imagen, $pointPolygonArray, count($pointPolygonArray) / 2, $color);
                 $pointPolygonArray = array();
                 $gid = $row[0];
                 array_push($pointPolygonArray, $row[1], $row[2]);
             }
         }
     }
     imagefilledpolygon($imagen, $pointPolygonArray, count($pointPolygonArray) / 2, $color);
     return $imagen;
 }
Beispiel #3
0
 /**
  * 获得彩色的验证码图片
  * @param array $paramArr 
  */
 public static function getCodeColorImage($paramArr)
 {
     $options = array('width' => 80, 'height' => 30, 'numCnt' => 4, 'inCode' => 'ABCD');
     if (is_array($paramArr)) {
         $options = array_merge($options, $paramArr);
     }
     extract($options);
     $img = imagecreate($width, $height);
     $bgcolor = self::getRandColor($img, 200);
     //背景色
     $fontCnt = 6;
     $numCnt = 4;
     $authCode = self::getAuthCode($inCode);
     for ($i = 0; $i < $numCnt; $i++) {
         $padding_left = rand(5, 10);
         $left = $padding_left + ($width - 10) * $i / $numCnt;
         //加入多边形色块干扰
         imagefilledpolygon($img, array(rand($left, $left + 20), rand(0, $height), rand($left, $left + 20), rand(0, $height), rand($left, $left + 20), rand(0, $height), rand($left, $left + 20), rand(0, $height), rand($left, $left + 20), rand(0, $height), rand($left, $left + 20), rand(0, $height), rand($left, $left + 20), rand(0, $height), rand($left, $left + 20), rand(0, $height), rand($left, $left + 20), rand(0, $height), rand($left, $left + 20), rand(0, $height)), 10, self::getRandColor($img, 180));
         $fontFile = SYSTEM_VAR . 'fonts/' . rand(1, $fontCnt) . '.ttf';
         imagettftext($img, rand(18, 24), rand(-30, 30), $left, rand(22, 26), self::getRandColor($img, 0, 120), $fontFile, $authCode[$i]);
     }
     //干扰像素,随机位置,随机颜色
     for ($i = 0; $i < 300; $i++) {
         $rand_x = rand(0, $width - 1);
         $rand_y = rand(0, $height - 1);
         imagesetpixel($img, $rand_x, $rand_y, self::getRandColor($img));
     }
     header("Content-type:image/png");
     imagepng($img);
     imagedestroy($img);
     exit;
 }
Beispiel #4
0
function genterate_flag($hex)
{
    $r = hexdec(substr($hex, 0, 2));
    $g = hexdec(substr($hex, 2, 2));
    $b = hexdec(substr($hex, 4, 2));
    // create a true colour, transparent image
    // turn blending OFF and draw a background rectangle in our transparent colour
    $default_size = 30;
    $size = $_REQUEST["size"];
    if ($size == '') {
        $size = $default_size;
    }
    $iwidth = $size;
    $iheight = $size;
    $image = imagecreatetruecolor($iwidth, $iheight);
    //
    imagealphablending($image, false);
    $col = imagecolorallocatealpha($image, 255, 255, 255, 127);
    $newc = imagecolorallocate($image, $r, $g, $b);
    $black = imagecolorallocatealpha($image, 0, 0, 0, 50);
    imagefilledrectangle($image, 0, 0, $iwidth, $iheight, $col);
    //imagefilledrectangle($image,10,10,($iwidth -10) ,($iheight-10),$newc);
    $values = array(0, $size / 10, 0, $size / 2, $size / 2, $size, $size, $size / 2, $size / 2, 0, $size / 10, 0);
    imagefilledpolygon($image, $values, 6, $newc);
    //imagefilledellipse($image, $size / 5, $size / 5 , $size / 8 , $size / 8, $black);
    imagefilledellipse($image, $size / 5, $size / 5, $size / 6, $size / 6, $col);
    //imagefilledpolygon($image , $values , 4 , $col );
    // imagealphablending($image,true);
    // ^^ Alpha blanding is back on.
    // insert image manipulation stuff in here
    // output the results...
    imagealphablending($image, true);
    // imagesavealpha($image,true);
    return $image;
}
 /**
  * Add method
  *
  * @return void Redirects on successful add, renders view otherwise.
  */
 public function add()
 {
     $mask = $this->Masks->newEntity();
     if ($this->request->is('post')) {
         $mask = $this->Masks->patchEntity($mask, $this->request->data);
         if ($this->Masks->save($mask)) {
             //draw thumbnail
             $virtualimage = imagecreate(100, 100);
             $fillcolor = imagecolorallocate($virtualimage, 0, 0, 0);
             $bg = imagecolorallocate($virtualimage, 239, 239, 239);
             imagefilledrectangle($virtualimage, 0, 0, 100, 100, $bg);
             $points = explode(",", $this->request->data['polygon']);
             foreach ($points as $key => $point) {
                 $points[$key] = (int) ((double) trim($point) * 100);
             }
             imagefilledpolygon($virtualimage, $points, count($points) / 2, $fillcolor);
             if (imagejpeg($virtualimage, WWW_ROOT . 'img' . DS . 'maskthumbs' . DS . $mask->id . '.jpg')) {
                 $this->Flash->success(__('The mask has been saved.'));
                 return $this->redirect(['action' => 'index']);
             } else {
                 $this->Flash->error(__('The mask thumbnail could not be created. Please, try again.'));
             }
         } else {
             $this->Flash->error(__('The mask could not be saved. Please, try again.'));
         }
     }
     $this->set(compact('mask'));
     $this->set('_serialize', ['mask']);
 }
Beispiel #6
0
function draw_axises($im_width, $im_height)
{
    global $im, $black, $l_grey, $x0, $y0, $maxX, $maxY, $minX, $minY, $red;
    global $string_x_start, $string_x_end, $string_y_start, $string_y_end;
    global $im, $black, $l_grey, $x0, $y0, $maxX, $maxY, $startX, $startY, $minX, $minY;
    $maxX = $im_width - 25.0;
    $maxY = $im_height - 20.0;
    $minY = $maxY - $minY - 20.0;
    imageline($im, 25.0, $minY + 20.0, $maxX, $minY + 20.0, $black);
    imageline($im, $minX + 25.0, 20.0, $minX + 25.0, $maxY, $black);
    $xArrow[0] = $maxX - 6;
    $xArrow[1] = $minY + 20 - 2;
    $xArrow[2] = $maxX;
    $xArrow[3] = $minY + 20;
    $xArrow[4] = $maxX - 6;
    $xArrow[5] = $minY + 20 + 2;
    imagefilledpolygon($im, $xArrow, 3, $black);
    $yArrow[0] = $minX + 25 - 2;
    $yArrow[1] = 20 + 6;
    $yArrow[2] = $minX + 25;
    $yArrow[3] = 20;
    $yArrow[4] = $minX + 25 + 2;
    $yArrow[5] = 20 + 6;
    imagefilledpolygon($im, $yArrow, 3, $black);
    imagestring($im, 2, 25.0, $minY + 20.0, $string_x_start, $black);
    imagestring($im, 2, $maxX, $minY + 20.0, $string_x_end, $black);
    imagestring($im, 2, $minX + 15.0, 20.0, $string_y_end, $black);
}
Beispiel #7
0
function draw_axises($im_width, $im_heignt)
{
    global $im, $black, $l_grey, $x0, $y0, $maxX, $maxY, $minXVal, $minYVal;
    $x0 = 25.0;
    //начало оси координат по X
    $y0 = 20.0;
    //начало оси координат по Y
    $maxX = $im_width - $x0;
    //максимальное значение оси координат по X в пикселах
    $maxY = $im_heignt - $y0;
    //максимальное значение оси координат по Y в пикселах
    imageline($im, $x0, $maxY, $maxX + 5, $maxY, $black);
    //рисуем ось X
    imageline($im, $x0, $y0 - 5, $x0, $maxY, $black);
    //рисуем ось Y
    //рисуем стрелку на оси X
    $xArrow[0] = $maxX + 2;
    $xArrow[1] = $maxY - 2;
    $xArrow[2] = $maxX + 8;
    $xArrow[3] = $maxY;
    $xArrow[4] = $maxX + 2;
    $xArrow[5] = $maxY + 2;
    imagefilledpolygon($im, $xArrow, 3, $black);
    //рисуем стрелку на оси Y
    $yArrow[0] = $x0 - 2;
    $yArrow[1] = $y0 - 2;
    $yArrow[2] = $x0;
    $yArrow[3] = $y0 - 8;
    $yArrow[4] = $x0 + 2;
    $yArrow[5] = $y0 - 2;
    imagefilledpolygon($im, $yArrow, 3, $black);
}
 private function _drawLine($image, $x1, $y1, $x2, $y2)
 {
     $thick = $this->_thickness->getThickness();
     $color = $this->_getDrawColor($image);
     if ($thick == 1) {
         return imageline($image, $x1, $y1, $x2, $y2, $color);
     }
     if ($this->hasTransparency() && $this->_transparency->getTransparency() != ParamTransparency::$minAlpha) {
         $t = $thick / 2 - 0.5;
         if ($x1 == $x2 || $y1 == $y2) {
             return imagefilledrectangle($image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
         }
         $k = ($y2 - $y1) / ($x2 - $x1);
         //y = kx + q
         $a = $t / sqrt(1 + pow($k, 2));
         $points = array(round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a), round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a), round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a), round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a));
         imagefilledpolygon($image, $points, 4, $color);
         imagepolygon($image, $points, 4, $color);
     } else {
         imagesetthickness($image, $thick);
         imageline($image, $x1, $y1, $x2, $y2, $color);
         imagesetthickness($image, 1);
         imagefilledellipse($image, $x1, $y1, $thick, $thick, $color);
         imagefilledellipse($image, $x2, $y2, $thick, $thick, $color);
         imageellipse($image, $x1, $y1, $thick, $thick, $color);
         imageellipse($image, $x2, $y2, $thick, $thick, $color);
     }
 }
Beispiel #9
0
 /**
  * renders the current captcha image
  */
 function showImage()
 {
     $image = imagecreatetruecolor($this->width, $this->height);
     $width = imagesx($image);
     $height = imagesy($image);
     $black = imagecolorallocate($image, 0, 0, 0);
     $white = imagecolorallocate($image, 250, 250, 250);
     $red = imagecolorallocatealpha($image, 225, 225, 225, 75);
     $green = imagecolorallocatealpha($image, 150, 150, 150, 75);
     $blue = imagecolorallocatealpha($image, 200, 200, 200, 75);
     imagefilledrectangle($image, 0, 0, $width, $height, $white);
     imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $red);
     $points = array(rand(0, 150), rand(0, 50), rand(0, 150), rand(0, 50), rand(0, 150), rand(0, 50), rand(0, 150), rand(0, 50), rand(0, 150), rand(0, 50), rand(0, 150), rand(0, 50));
     imagefilledpolygon($image, $points, 4, $blue);
     imagefilledpolygon($image, array_reverse($points), 6, $green);
     imagefilledrectangle($image, 0, 0, $width, 0, $black);
     imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black);
     imagefilledrectangle($image, 0, 0, 0, $height - 1, $black);
     imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black);
     for ($i = 0; $i < 50; $i++) {
         //imagefilledrectangle($im, $i + $i2, 5, $i + $i3, 70, $black);
         imagesetthickness($image, rand(1, 5));
         imagearc($image, rand(1, 150), rand(1, 50), rand(1, 150), rand(1, 50), rand(1, 150), rand(1, 50), rand(0, 1) ? $green : $red);
     }
     if (function_exists("imagettftext")) {
         $font = DIR_ROOT . 'view/fonts/Duality.ttf';
         imagettftext($image, 24, rand(-5, 5), intval(($width - strlen($this->code) * 10) / 2), intval(($height + 10) / 2), $black, $font, $this->code);
     } else {
         imagestring($image, 5, intval(($width - strlen($this->code) * 9) / 2), intval(($height - 15) / 2), $this->code, $black);
     }
     header('Content-type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
 }
Beispiel #10
0
 function leftPointer($image, $xpoint, $ypoint, $colour)
 {
     $black = imagecolorallocate($image, 0x0, 0x0, 0x0);
     $values = array($xpoint + 13, $ypoint - 1, $xpoint + 10, $ypoint - 1, $xpoint + 10, $ypoint - 5, $xpoint + 3, $ypoint + 2, $xpoint + 10, $ypoint + 9, $xpoint + 10, $ypoint + 5, $xpoint + 13, $ypoint + 5);
     imagefilledpolygon($image, $values, 7, $colour);
     imagepolygon($image, $values, 7, $black);
 }
Beispiel #11
0
 public function diagonalCross($img, $width, $height, $backColour, $crossColour)
 {
     $smallest = min($width, $height);
     //Make the width of the lines 20% of the smallest
     $lineWidth = $smallest * 0.2;
     $halfLine = $lineWidth / 2;
     //Draw the polygons in the background colour instead of drawing the lines, as when the lines overlap, the opacity changes in the overlap space
     $topPolyPointX = $width / 2;
     $topPolyPointY = $height / 2 - $halfLine;
     $topPolyEndX = $width - $halfLine;
     $bottomPolyPointX = $width / 2;
     $bottomPolyPointY = $height / 2 + $halfLine;
     $bottomPolyEndX = $width - $halfLine;
     $leftPolyPointX = $width / 2 - $halfLine;
     $leftPolyPointY = $height / 2;
     $leftPolyEndY = $height - $halfLine;
     $rightPolyPointX = $width / 2 + $halfLine;
     $rightPolyPointY = $height / 2;
     $rightPolyEndY = $height - $halfLine;
     imagefilledrectangle($img, 0, 0, $width, $height, $crossColour);
     imagefilledpolygon($img, array($halfLine, 0, $topPolyPointX, $topPolyPointY, $topPolyEndX, 0), 3, $backColour);
     imagefilledpolygon($img, array($halfLine, $height, $bottomPolyPointX, $bottomPolyPointY, $bottomPolyEndX, $height), 3, $backColour);
     imagefilledpolygon($img, array(0, $halfLine, $leftPolyPointX, $leftPolyPointY, 0, $leftPolyEndY), 3, $backColour);
     imagefilledpolygon($img, array($width, $halfLine, $rightPolyPointX, $rightPolyPointY, $width, $rightPolyEndY), 3, $backColour);
     return $img;
 }
 /**
  * Draws this object onto an image
  *
  * @param   img.Image image
  * @return  var
  */
 public function draw($image)
 {
     if ($this->fill) {
         return imagefilledpolygon($image->handle, $this->points, sizeof($this->points) / 2, $this->col->handle);
     } else {
         return imagepolygon($image->handle, $this->points, sizeof($this->points) / 2, $this->col->handle);
     }
 }
Beispiel #13
0
 function fill($transform, $image, $color)
 {
     $coords = $this->getPointArray();
     $size = $this->getPointCount();
     for ($i = 0; $i < $size; $i++) {
         $transform->apply($coords[$i * 2], $coords[$i * 2 + 1]);
     }
     imagefilledpolygon($image, $coords, $size, $color);
 }
 protected function renderFill($image, array $params, $color)
 {
     if ($params['numpoints'] < 3) {
         return;
     }
     // somehow imagesetthickness() affects the polygon drawing. reset to 0.
     imagesetthickness($image, 0);
     imagefilledpolygon($image, $params['points'], $params['numpoints'], $color);
 }
 public function generate()
 {
     $color = $this->hex2dec($this->color);
     $im = imagecreate($this->size, $this->size);
     imagefill($im, 0, 0, imagecolorallocate($im, $this->bgColorRGB[0], $this->bgColorRGB[1], $this->bgColorRGB[2]));
     $color = imagecolorallocate($im, $color[0], $color[1], $color[2]);
     imagefilledpolygon($im, array($this->size / 2, 0, $this->size, $this->size / 2, $this->size / 2, $this->size, 0, $this->size / 2), 4, $color);
     $this->image = $im;
     $this->markerSize = $this->size / 1.01;
     return $im;
 }
Beispiel #16
0
 /**
  * Draw polygon on given GD resource
  *
  * @param  resource $resource
  * @param  integer  $x
  * @param  interger $y
  * @return boolean
  */
 private function applyToResource($resource, $x, $y)
 {
     $background = new Color($this->background);
     imagefilledpolygon($resource, $this->points, intval(count($this->points) / 2), $background->getInt());
     if ($this->hasBorder()) {
         $border_color = new Color($this->border_color);
         imagesetthickness($resource, $this->border_width);
         imagepolygon($resource, $this->points, intval(count($this->points) / 2), $border_color->getInt());
     }
     return true;
 }
Beispiel #17
0
 private function draw()
 {
     $image = imagecreatetruecolor($this->size, $this->size);
     imagealphablending($image, true);
     imagefilledrectangle($image, 0, 0, $this->size, $this->size, imagecolorallocatealpha($image, 0, 0, 0, 0));
     foreach ($this->polygons as $polygon) {
         $color = imagecolorallocatealpha($image, $polygon[0], $polygon[0], $polygon[0], $polygon[1]);
         imagefilledpolygon($image, array_slice($polygon, 2), count($polygon) / 2 - 1, $color);
     }
     return $image;
 }
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;
}
Beispiel #19
0
 /**
  * Draw polygon on given image
  *
  * @param  Image   $image
  * @param  integer $x
  * @param  integer $y
  * @return boolean
  */
 public function applyToImage(Image $image, $x = 0, $y = 0)
 {
     $background = new Color($this->background);
     imagefilledpolygon($image->getCore(), $this->points, intval(count($this->points) / 2), $background->getInt());
     if ($this->hasBorder()) {
         $border_color = new Color($this->border_color);
         imagesetthickness($image->getCore(), $this->border_width);
         imagepolygon($image->getCore(), $this->points, intval(count($this->points) / 2), $border_color->getInt());
     }
     return true;
 }
Beispiel #20
0
 public function drawAxis($vImage, $vColor, $iPosX = 0, $iPosY = false)
 {
     if ($iPosY === false) {
         $iPosY = imagesy($vImage);
     }
     $vImageWidth = imagesx($vImage);
     imageline($vImage, $iPosX, $iPosY, $iPosX, 0, $vColor);
     imageline($vImage, $iPosX, $iPosY, $vImageWidth, $iPosY, $vColor);
     imagefilledpolygon($vImage, array($iPosX, 0, $iPosX - 3, 5, $iPosX + 3, 5), 3, $vColor);
     imagefilledpolygon($vImage, array($vImageWidth, $iPosY, $vImageWidth - 5, $iPosY - 3, $vImageWidth - 5, $iPosY + 3), 3, $vColor);
 }
Beispiel #21
0
 /**
  * Method displaying the graphical polygon.
  *
  * @param Container $container Image in which display the element
  * @param int $x_margin left margin
  * @param int $y_margin top margin
  * @return false if something wrong
  */
 function display($container, $x_margin = 0, $y_margin = 0)
 {
     $image = $container->getImage();
     $color = imagecolorallocate($image, $this->_r_color, $this->_g_color, $this->_b_color);
     $x_margin = $this->_x_margin + $x_margin;
     $y_margin = $this->_y_margin + $y_margin;
     $values = array();
     for ($i = 0; $i < count($this->_coordinates); $i = $i + 2) {
         $values[$i] = $this->_coordinates[$i] + $x_margin;
         $values[$i + 1] = $this->_coordinates[$i + 1] + $y_margin;
     }
     return imagefilledpolygon($image, $values, count($values) / 2, $color);
 }
Beispiel #22
0
 /**
  * {@inheritdoc}
  */
 protected function execute(array $arguments)
 {
     $success = TRUE;
     if ($arguments['fill_color']) {
         $color = $this->allocateColorFromRgba($arguments['fill_color']);
         $success = imagefilledpolygon($this->getToolkit()->getResource(), $this->getRectangleCorners($arguments['rectangle']), 4, $color);
     }
     if ($success && $arguments['border_color']) {
         $color = $this->allocateColorFromRgba($arguments['border_color']);
         $success = imagepolygon($this->getToolkit()->getResource(), $this->getRectangleCorners($arguments['rectangle']), 4, $color);
     }
     return $success;
 }
Beispiel #23
0
 /** 生成验证码图片
  * @param  int	$length 驗證碼長度
  * @param  Array	$param  參數
  * @return IMG
  */
 public function create($length = 4, $param = array())
 {
     Header("Content-type: image/PNG");
     $authnum = $this->random($length);
     //生成验证码字符.
     $width = isset($param['width']) ? $param['width'] : 13;
     //文字宽度
     $height = isset($param['height']) ? $param['height'] : 18;
     //文字高度
     $pnum = isset($param['pnum']) ? $param['pnum'] : 100;
     //干扰象素个数
     $lnum = isset($param['lnum']) ? $param['lnum'] : 2;
     //干扰线条数
     $this->captcha_session($this->sname, $authnum);
     //將隨機數寫入session
     $pw = $width * $length + 10;
     $ph = $height + 6;
     $im = imagecreate($pw, $ph);
     //imagecreate() 新建图像,大小为 x_size 和 y_size 的空白图像。
     $black = ImageColorAllocate($im, 238, 238, 238);
     //设置背景颜色
     $values = array(mt_rand(0, $pw), mt_rand(0, $ph), mt_rand(0, $pw), mt_rand(0, $ph), mt_rand(0, $pw), mt_rand(0, $ph), mt_rand(0, $pw), mt_rand(0, $ph), mt_rand(0, $pw), mt_rand(0, $ph), mt_rand(0, $pw), mt_rand(0, $ph));
     imagefilledpolygon($im, $values, 6, ImageColorAllocate($im, mt_rand(170, 255), mt_rand(200, 255), mt_rand(210, 255)));
     //設置干擾多邊形底圖
     /* 文字 */
     for ($i = 0; $i < strlen($authnum); $i++) {
         $font = ImageColorAllocate($im, mt_rand(0, 50), mt_rand(0, 150), mt_rand(0, 200));
         //设置文字颜色
         $x = $i / $length * $pw + rand(1, 6);
         //设置随机X坐标
         $y = rand(1, $ph / 3);
         //设置随机Y坐标
         imagestring($im, mt_rand(4, 6), $x, $y, substr($authnum, $i, 1), $font);
     }
     /* 加入干扰象素 */
     for ($i = 0; $i < $pnum; $i++) {
         $dist = ImageColorAllocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         //设置杂点颜色
         imagesetpixel($im, mt_rand(0, $pw), mt_rand(0, $ph), $dist);
     }
     /* 加入干擾線 */
     for ($i = 0; $i < $lnum; $i++) {
         $dist = ImageColorAllocate($im, mt_rand(50, 255), mt_rand(150, 255), mt_rand(200, 255));
         //設置線顏色
         imageline($im, mt_rand(0, $pw), mt_rand(0, $ph), mt_rand(0, $pw), mt_rand(0, $ph), $dist);
     }
     ImagePNG($im);
     //以 PNG 格式将图像输出到浏览器或文件
     ImageDestroy($im);
     //销毁一图像
 }
Beispiel #24
0
    /**
     * Draws a polygon on the handle
     *
     * @param GD-object $handle The handle on which the polygon is drawn
     * @param Zend_Image_Action_DrawPolygon $polygonObject The object that with all info
     */
    public function perform(Zend_Image_Adapter_Gd $adapter, Zend_Image_Action_DrawPolygon $polygonObject) { // As of ZF2.0 / PHP5.3, this can be made static.
        $handle = $adapter->getHandle();
    
        $points = $this->_parsePoints($polygonObject->getPoints());
        
        if(($pattern = $polygonObject->getStrokeDashPattern())!== null) {
            $color = imagecolorallocate($handle, 0, 255, 0);
            $array = array();
            foreach($pattern as $amountOfPixels) {
                $array = array_merge($array, array_fill(0, $amountOfPixels, $color));
                $array = array_merge($array, array_fill(0, $polygonObject->getStrokeDashOffset(), IMG_COLOR_TRANSPARENT));
            }
            
            if(count($array) > 0) {
                imagesetstyle($handle, $array);
            }
        }
        
        
        
        if($polygonObject->isFilled()) {
            //@TODO: extract this to Zend_Image_Adapter_Gd_Action_ActionAbstract ?
            $color = $polygonObject->getFillColor()->getRgb();
            $colorRes = imagecolorallocatealpha($handle,
                                               $color['red'],
                                               $color['green'],
                                               $color['blue'],
                                               $polygonObject->getFillAlpha());
            
            imagefilledpolygon($handle, $points, count($points)/2, $colorRes);
        }
        
        $points = $polygonObject->getPoints();
        $start = current($points);;
        $line = new Zend_Image_Action_DrawLine();
        while(current($points)!==false) {
            $from = current($points);
            $to = next($points);
            if($to===false) {
                if(!$polygonObject->isClosed()) {
                    break;
                } else {
                    $to = $start;
                }
            }

            $line->from($from);
            $line->to($to);
            $line->perform($adapter);
        }
    }
Beispiel #25
0
 function CaptchaImages($code, $width = 145, $height = 35)
 {
     /* select the type of font, must be used in directoy in which script is being called into */
     $this->font = dirname(__FILE__) . '/CALIBRI.TTF';
     $font_size = $height * 0.6;
     $image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
     /* set the colours */
     $bgR = mt_rand(0, 255);
     $bgG = mt_rand(0, 255);
     $bgB = mt_rand(0, 255);
     $background_color = imagecolorallocate($image, $bgR, $bgG, $bgB);
     $noise_color = imagecolorallocate($image, abs(100 - $bgR), abs(100 - $bgG), abs(100 - $bgB));
     $text_color = imagecolorallocate($image, abs(255 - $bgR), abs(255 - $bgG), abs(255 - $bgB));
     /* generate random dots in background */
     for ($i = 0; $i < $width * $height / 3; $i++) {
         imagefilledellipse($image, mt_rand(0, $width), mt_rand(0, $height), 1, 1, $noise_color);
     }
     /* generate random lines in background */
     for ($i = 0; $i < $width * $height / 150; $i++) {
         imageline($image, mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $height), $noise_color);
     }
     /* set random colors */
     $w = imagecolorallocate($image, abs(100 - $bgR), abs(100 - $bgG), abs(100 - $bgB));
     $r = imagecolorallocate($image, abs(100 - $bgR), abs(100 - $bgG), abs(100 - $bgB));
     /* Draw a dashed line, 5 red pixels, 5 white pixels */
     $style = array($r, $r, $r, $r, $r, $w, $w, $w, $w, $w);
     imagesetstyle($image, $style);
     imageline($image, 0, 0, $width, $height, IMG_COLOR_STYLED);
     imageline($image, $width, 0, 0, $height, IMG_COLOR_STYLED);
     /* create random polygon points */
     $values = array(mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width), mt_rand(0, $width), mt_rand(0, $height), mt_rand(0, $height), mt_rand(0, $width));
     /* create Random Colors then set it to $clr */
     $r = abs(100 - mt_rand(0, 255));
     $g = abs(100 - mt_rand(0, 255));
     $b = abs(100 - mt_rand(0, 255));
     $clr = imagecolorallocate($image, $r, $g, $b);
     /* create filled polygon with random points */
     imagefilledpolygon($image, $values, 6, $clr);
     $textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
     $x = ($width - $textbox[4]) / 2;
     $y = ($height - $textbox[5]) / 2;
     imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font, $code) or die('Error in imagettftext function');
     /* pretty it */
     imageantialias($image, 100);
     imagealphablending($image, 1);
     imagelayereffect($image, IMG_EFFECT_OVERLAY);
     /* output captcha image to browser */
     header('Content-Type: image/jpeg');
     imagejpeg($image);
     imagedestroy($image);
 }
Beispiel #26
0
/**
 * No RRD files found that could match request
 * @code HTTP error code
 * @code_msg Short text description of HTTP error code
 * @title Title for fake RRD graph
 * @msg Complete error message to display in place of graph content
 */
function error($code, $code_msg, $title, $msg) {
	global $config;
	header(sprintf("HTTP/1.0 %d %s", $code, $code_msg));
	header("Pragma: no-cache");
	header("Expires: Mon, 01 Jan 2008 00:00:00 CET");
	header("Content-Type: image/png");
	$w = $config['rrd_width']+81;
	$h = $config['rrd_height']+79;

	$png     = imagecreate($w, $h);
	$c_bkgnd = imagecolorallocate($png, 240, 240, 240);
	$c_fgnd  = imagecolorallocate($png, 255, 255, 255);
	$c_blt   = imagecolorallocate($png, 208, 208, 208);
	$c_brb   = imagecolorallocate($png, 160, 160, 160);
	$c_grln  = imagecolorallocate($png, 114, 114, 114);
	$c_grarr = imagecolorallocate($png, 128,  32,  32);
	$c_txt   = imagecolorallocate($png, 0, 0, 0);
	$c_etxt  = imagecolorallocate($png, 64, 0, 0);

	if (function_exists('imageantialias'))
		imageantialias($png, true);
	imagefilledrectangle($png, 0,   0, $w, $h, $c_bkgnd);
	imagefilledrectangle($png, 51, 33, $w-31, $h-47, $c_fgnd);
	imageline($png,  51,  30,  51, $h-43, $c_grln);
	imageline($png,  48, $h-46, $w-28, $h-46, $c_grln);
	imagefilledpolygon($png, array(49, 30,    51, 26,    53, 30), 3, $c_grarr);
	imagefilledpolygon($png, array($w-28, $h-48,  $w-24, $h-46,  $w-28, $h-44), 3, $c_grarr);
	imageline($png,    0,    0,   $w,    0, $c_blt);
	imageline($png,    0,    1,   $w,    1, $c_blt);
	imageline($png,    0,    0,    0,   $h, $c_blt);
	imageline($png,    1,    0,    1,   $h, $c_blt);
	imageline($png, $w-1,    0, $w-1,   $h, $c_brb);
	imageline($png, $w-2,    1, $w-2,   $h, $c_brb);
	imageline($png,    1, $h-2,   $w, $h-2, $c_brb);
	imageline($png,    0, $h-1,   $w, $h-1, $c_brb);

	imagestring($png, 4, ceil(($w-strlen($title)*imagefontwidth(4)) / 2), 10, $title, $c_txt);
	imagestring($png, 5, 60, 35, sprintf('%s [%d]', $code_msg, $code), $c_etxt);
	if (function_exists('imagettfbbox') && is_file($config['error_font'])) {
		// Detailled error message
		$fmt_msg = makeTextBlock($msg, $errorfont, 10, $w-86);
		$fmtbox  = imagettfbbox(12, 0, $errorfont, $fmt_msg);
		imagettftext($png, 10, 0, 55, 35+3+imagefontwidth(5)-$fmtbox[7]+$fmtbox[1], $c_txt, $errorfont, $fmt_msg);
	} else {
		imagestring($png, 4, 53, 35+6+imagefontwidth(5), $msg, $c_txt);
	}

	imagepng($png);
	imagedestroy($png);
}
 /**
  * it draws object on map
  *
  * @param Map $map
  */
 public function draw(Map $map)
 {
     $points = array();
     $count = 0;
     foreach ($this->_points as $point) {
         $coordinates = $map->getPixelPointFromCoordinates($point->getLon(), $point->getLat());
         $points[] = $coordinates['x'];
         $points[] = $coordinates['y'];
         $count++;
     }
     if ($count < 3) {
         return;
     }
     imagefilledpolygon($map->getImage(), $points, $count, $this->_getDrawColor($map->getImage()));
 }
/**
 *	Draws a thick line
 *	Changing the thickness of a line using imagesetthickness doesn't produce as nice of result
 *
 *	@param	object	$img
 *	@param	int		$startX
 *	@param	int		$startY
 *	@param	int		$endX
 *	@param	int		$endY
 *	@param	object	$colour
 *	@param	int		$thickness
 *
 *	@return	void
 */
function drawThickLine($img, $startX, $startY, $endX, $endY, $colour, $thickness)
{
    $angle = atan2($startY - $endY, $endX - $startX);
    $dist_x = $thickness * sin($angle);
    $dist_y = $thickness * cos($angle);
    $p1x = ceil($startX + $dist_x);
    $p1y = ceil($startY + $dist_y);
    $p2x = ceil($endX + $dist_x);
    $p2y = ceil($endY + $dist_y);
    $p3x = ceil($endX - $dist_x);
    $p3y = ceil($endY - $dist_y);
    $p4x = ceil($startX - $dist_x);
    $p4y = ceil($startY - $dist_y);
    $array = array(0 => $p1x, $p1y, $p2x, $p2y, $p3x, $p3y, $p4x, $p4y);
    imagefilledpolygon($img, $array, count($array) / 2, $colour);
}
Beispiel #29
0
 function line($x1, $y1, $x2, $y2, $Color, $Thickness = 1)
 {
     if ($Thickness == 1) {
         return imageline($this->Image, $x1, $y1, $x2, $y2, $Color);
     }
     $t = $Thickness / 2 - 0.5;
     if ($x1 == $x2 || $y1 == $y2) {
         return imagefilledrectangle($this->Image, round(min($x1, $x2) - $t), round(min($y1, $y2) - $t), round(max($x1, $x2) + $t), round(max($y1, $y2) + $t), $color);
     }
     $k = ($y2 - $y1) / ($x2 - $x1);
     //y = kx + q
     $a = $t / sqrt(1 + pow($k, 2));
     $Points = array(round($x1 - (1 + $k) * $a), round($y1 + (1 - $k) * $a), round($x1 - (1 - $k) * $a), round($y1 - (1 + $k) * $a), round($x2 + (1 + $k) * $a), round($y2 - (1 - $k) * $a), round($x2 + (1 - $k) * $a), round($y2 + (1 + $k) * $a));
     imagefilledpolygon($this->Image, $Points, 4, $Color);
     return imagepolygon($this->Image, $Points, 4, $Color);
 }
 private function drawCircle($x, $y, $radius)
 {
     $vertexArray = array();
     $angleStep = 360 / CircleBackgroundDrawer::VERTEX_COUNT;
     $angle = 0;
     for ($i = 0; $i < CircleBackgroundDrawer::VERTEX_COUNT; ++$i) {
         $color = $this->makeColor();
         $colorId = $this->getTuringImage()->getColorIdentifier($color);
         $angleRad = deg2rad($angle);
         $dx = sin($angleRad) * $radius;
         $dy = cos($angleRad) * $radius;
         $vertexArray[] = $x + $dx;
         $vertexArray[] = $y + $dy;
         $angle += $angleStep;
     }
     imagefilledpolygon($this->getTuringImage()->getImageId(), $vertexArray, CircleBackgroundDrawer::VERTEX_COUNT, $colorId);
 }