Exemplo n.º 1
0
 public function testAddPolygon()
 {
     $i = new Gd(__DIR__ . '/../tmp/test.jpg');
     $points = array(array('x' => 320, 'y' => 50), array('x' => 400, 'y' => 100), array('x' => 420, 'y' => 200), array('x' => 280, 'y' => 320), array('x' => 200, 'y' => 180));
     $i->setStrokeColor(new Rgb(0, 0, 0))->drawPolygon($points);
     $i->setBackgroundColor(new Rgb(255, 0, 0));
     $i->drawPolygon($points);
     $i->setFillColor(new Rgb(255, 0, 0));
     $i->drawPolygon($points);
     $this->assertEquals(640, $i->getWidth());
 }
Exemplo n.º 2
0
 /**
  * Create CAPTCHA image
  *
  * @return Captcha
  */
 public function createImage()
 {
     $image = new Gd('captcha.gif', $this->width, $this->height);
     $image->setBackgroundColor(255, 255, 255);
     $image->draw()->setStrokeColor($this->lineColor[0], $this->lineColor[1], $this->lineColor[2]);
     // Draw background grid
     for ($y = $this->lineSpacing; $y <= $this->height; $y += $this->lineSpacing) {
         $image->draw()->line(0, $y, $this->width, $y);
     }
     for ($x = $this->lineSpacing; $x <= $this->width; $x += $this->lineSpacing) {
         $image->draw()->line($x, 0, $x, $this->height);
     }
     $image->effect()->border($this->textColor, 0.5);
     $image->type()->setFillColor($this->textColor[0], $this->textColor[1], $this->textColor[2]);
     if (null === $this->font) {
         $image->type()->size(5);
         $textX = round(($this->width - $this->length * 10) / 2);
         $textY = round(($this->height - 16) / 2);
     } else {
         $image->type()->font($this->font)->size($this->size);
         $textX = round(($this->width - $this->length * ($this->size / 1.5)) / 2);
         $textY = round($this->height - ($this->height - $this->size) / 2 + (int) $this->rotate / 2);
     }
     $image->type()->xy($textX, $textY)->text($this->token['value']);
     $this->image = $image;
     return $this;
 }