Example #1
0
 public static function sample()
 {
     $i = new Image(200, 200, Image::PNG, 2);
     /**
      * Repere
      */
     $i->setLineStyle(255, 0, 0, 2);
     $i->moveTo(0, 100);
     $i->lineTo(200, 100);
     $i->moveTo(100, 0);
     $i->lineTo(100, 200);
     /**
      * Carre
      */
     $i->setLineStyle(127, 127, 127, 2);
     $i->beginFill(255, 255, 255);
     $i->drawRectangle(50, 50, 100, 100);
     $i->endFill();
     /**
      * Cercle
      */
     $i->setLineStyle(0, 0, 0, 0);
     $i->beginFill(0, 0, 255);
     $i->drawCircle(50, 50, 10);
     $i->endFill();
     /**
      * texte
      */
     $i->drawText("x", 10, "files/visitor2.ttf", 0, 97);
     $i->drawText("y", 10, "files/visitor2.ttf", 87, 10);
     $i->drawText("class.Image.php", 10, "files/arial.ttf", 65, 140, 45, 45, 45, 45);
     $i->render();
 }
Example #2
0
 /**
  * @return void
  */
 public function render()
 {
     if (empty($this->fontColors)) {
         $this->fontColors[] = "#000000";
     }
     if (!$this->fontSizeMax) {
         $this->fontSizeMax = 12;
     }
     if (!$this->fontSizeMin) {
         $this->fontSizeMin = 12;
     }
     $distance = $this->width / $this->length;
     $_SESSION[self::SESSION_VAR_NAME][$this->name] = $this->value;
     $img = new Image($this->width, $this->height, Image::PNG, 1);
     if (!$this->transparent) {
         $img->beginFill(hexdec(substr($this->backgroundColor, 1, 2)), hexdec(substr($this->backgroundColor, 3, 2)), hexdec(substr($this->backgroundColor, 5, 2)));
     }
     $img->drawRectangle(0, 0, $this->width, $this->height);
     $img->endFill();
     $value = $this->getValue();
     for ($i = 0, $max = strlen($value); $i < $max; $i++) {
         $c = $this->fontColors[rand(0, count($this->fontColors) - 1)];
         $f = $this->fonts[rand(0, count($this->fonts) - 1)];
         $s = rand($this->fontSizeMin, $this->fontSizeMax);
         $img->drawText(substr($value, $i, 1), $s, $f, $distance / 4 + $i * $distance, $s + ($this->height - $s) / 2, hexdec(substr($c, 1, 2)), hexdec(substr($c, 3, 2)), hexdec(substr($c, 5, 2)), rand(-$this->rotation, $this->rotation));
     }
     $img->render();
 }