Exemple #1
0
/**
 * display any message as a PNG image
 *
 * @param string $txt message to be displayed
 */
function ImageFlushError($txt)
{
    Header('Content-Type: image/png');
    $image = imagecreate(safe_GET_integer('width', 100, 1000, 400), safe_GET_integer('height', 40, 400, 100));
    $bg = imagecolorallocate($image, 0xee, 0xee, 0xee);
    $red = Imagecolorallocate($image, 0xff, 0x0, 0x0);
    imagestring($image, 2, 10, 10, $txt, $red);
    imagepng($image);
}
Exemple #2
0
 private function create_do()
 {
     $this->im = Imagecreate($this->config['width'], $this->config['height']);
     //设置背景为白色
     Imagecolorallocate($this->im, $this->config['color'][0], $this->config['color'][1], $this->config['color'][2]);
     //为此背景加个边框
     if ($this->config['boxline'] == True) {
         $bordercolor = Imagecolorallocate($this->im, 37, 37, 37);
         Imagerectangle($this->im, 0, 0, $this->config['width'] - 1, $this->config['height'] - 1, $bordercolor);
     }
     //生成验证码
     $this->create_str();
     $coder = $_SESSION[$this->config['codname']];
     //输入文字
     $fontcolor = Imagecolorallocate($this->im, 46, 46, 46);
     for ($i = 0; $i < $this->config['length']; $i++) {
         Imagestring($this->im, 5, $i * 10 + 6, rand(2, 5), $coder[$i], $fontcolor);
     }
     //加入干扰线
     $interfere = $this->config['interfere'];
     $interfere = $interfere > 30 ? "30" : $interfere;
     if (!empty($interfere) && $interfere > 1) {
         for ($i = 1; $i < $interfere; $i++) {
             $linecolor = Imagecolorallocate($this->im, rand(0, 255), rand(0, 255), rand(0, 255));
             $x = rand(1, $this->config['width']);
             $y = rand(1, $this->config['height']);
             $x2 = rand($x - 10, $x + 10);
             $y2 = rand($y - 10, $y + 10);
             Imageline($this->im, $x, $y, $x2, $y2, $linecolor);
         }
     }
     ob_clean();
     Header("Pragma:no-cache\r\n");
     Header("Cache-Control:no-cache\r\n");
     Header("Expires:0\r\n");
     Header("Content-type:Image/jpeg\r\n");
     Imagejpeg($this->im);
     Imagedestroy($this->im);
     exit;
 }
 /**
  * Draw
  *
  * @return image resource
  */
 public function draw()
 {
     // Create image
     $im = imageCreate($this->matrixSize, $this->matrixSize);
     // Colours used in Barcode
     $color = array(Imagecolorallocate($im, 255, 255, 255), Imagecolorallocate($im, 0, 0, 0));
     for ($y = 0; $y < $this->matrixSize; $y++) {
         for ($x = 0; $x < $this->matrixSize; $x++) {
             imagesetpixel($im, $x, $y, $color[$this->matrix[$y][$x]]);
         }
     }
     $dimension = $this->symbolSize * $this->moduleSize;
     $dimensionNoQuiet = $this->matrixSize * $this->moduleSize;
     $out = ImageCreate($dimension, $dimension);
     Imagecolorallocate($out, 255, 255, 255);
     $move = self::QUIET_ZONE * $this->moduleSize;
     // resize image and add quiet zone
     imagecopyresized($out, $im, $move, $move, 0, 0, $dimensionNoQuiet, $dimensionNoQuiet, $this->matrixSize, $this->matrixSize);
     return $out;
 }
 /**
  * Draw
  * Create image with barcode
  *
  * @param bool $showText
  * @return image resource
  */
 public function draw($showText = true)
 {
     // Image create
     $margin = $this->margin * $this->moduleSize;
     $im = ImageCreate($this->getBarcodeLen() * $this->moduleSize + 2 * $margin, $this->height + $this->fontSize + 2 * $margin);
     // Color set
     $white = Imagecolorallocate($im, 255, 255, 255);
     $black = Imagecolorallocate($im, 0, 0, 0);
     // Draw lines
     $pos = 0;
     foreach ($this->biteCode as $type => $values) {
         switch ($type) {
             case 'DATA':
             case 'DATA2':
                 // Data
                 for ($i = 0; $i < strlen($values); $i++) {
                     $color = $values[$i] == '1' ? $black : $white;
                     imagefilledrectangle($im, $pos * $this->moduleSize + $margin, $margin, ($pos + 1) * $this->moduleSize + $margin, $this->height - 5 * $this->moduleSize + $margin, $color);
                     $pos++;
                 }
                 break;
             default:
                 // Special chars
                 // will be longer
                 for ($i = 0; $i < strlen($values); $i++) {
                     $color = $values[$i] == '1' ? $black : $white;
                     imagefilledrectangle($im, $pos * $this->moduleSize + $margin, $margin, ($pos + 1) * $this->moduleSize + $margin, $this->height + $margin, $color);
                     $pos++;
                 }
                 break;
         }
     }
     // Text
     if ($showText) {
         $textWidth = ImageFontWidth($this->fontSize) * strlen($this->text);
         imagestring($im, $this->fontSize, $this->getBarcodeLen() * $this->moduleSize / 2 - $textWidth / 2 + $margin, $this->height - $this->fontSize / 2 + $margin, $this->text, $black);
     }
     return $im;
 }
Exemple #5
0
 /**
  * Draw
  * 
  * @param bool $showText
  * @return image resource 
  */
 public function draw($showText = true)
 {
     $im = parent::draw(false);
     $margin = $this->margin * $this->moduleSize;
     $white = Imagecolorallocate($im, 255, 255, 255);
     $black = Imagecolorallocate($im, 0, 0, 0);
     if ($showText) {
         $im2 = ImageCreate($this->getBarcodeLen() * $this->moduleSize + 2 * $margin + $margin, $this->height + $this->fontSize + 2 * $margin);
         imagecopy($im2, $im, $margin, 0, 0, 0, $this->getBarcodeLen() * $this->moduleSize + 2 * $margin, $this->height + $this->fontSize + 2 * $margin);
         $charsA = $this->text[0];
         for ($i = 1; $i <= strlen($this->text); $i++) {
             if ($i <= 6) {
                 $charsB .= $this->text[$i];
             } else {
                 $charsC .= $this->text[$i];
             }
         }
         $textWidth = ImageFontWidth($this->fontSize) * strlen($charsB);
         imagestring($im2, $this->fontSize, $this->getBarcodeLen() * $this->moduleSize / 4 - $textWidth / 2 + 2 * $margin, $this->height - $this->fontSize / 2 + $margin, $charsB, $black);
         $textWidth = ImageFontWidth($this->fontSize) * strlen($charsC);
         imagestring($im2, $this->fontSize, $this->getBarcodeLen() * $this->moduleSize - $this->getBarcodeLen() * $this->moduleSize / 4 - $textWidth / 2 + 2 * $margin, $this->height - $this->fontSize / 2 + $margin, $charsC, $black);
     }
     return $im2;
 }
 /**
  * Draw
  * Add text into barcode
  *
  * @param bool $showText
  * @return image resource
  */
 public function draw($showText = true)
 {
     $im = parent::draw(false);
     $margin = $this->margin * $this->moduleSize;
     $white = Imagecolorallocate($im, 255, 255, 255);
     $black = Imagecolorallocate($im, 0, 0, 0);
     if ($showText) {
         // Increase space between symbol 2x
         $im2 = ImageCreate($this->getBarcodeLen() * $this->moduleSize + 2 * $margin + $margin, $this->height + $this->fontSize + 2 * $margin);
         imagecopy($im2, $im, $margin, 0, 0, 0, $this->getBarcodeLen() * $this->moduleSize + 2 * $margin, $this->height + $this->fontSize + 2 * $margin);
         // Divide text into three parts and each insert to the diffrerent place
         $charsA = $this->text[0];
         // first char
         for ($i = 1; $i <= strlen($this->text); $i++) {
             if ($i <= 6) {
                 $charsB .= $this->text[$i];
             } else {
                 $charsC .= $this->text[$i];
             }
         }
         // Insert A
         $textWidth = ImageFontWidth($this->fontSize) * strlen($charsA);
         imagestring($im2, $this->fontSize, $margin, $this->height - $this->fontSize / 2 + $margin, $charsA, $black);
         // Insert B
         $textWidth = ImageFontWidth($this->fontSize) * strlen($charsB);
         imagestring($im2, $this->fontSize, $this->getBarcodeLen() * $this->moduleSize / 4 - $textWidth / 2 + 2 * $margin, $this->height - $this->fontSize / 2 + $margin, $charsB, $black);
         // Insert C
         $textWidth = ImageFontWidth($this->fontSize) * strlen($charsC);
         imagestring($im2, $this->fontSize, $this->getBarcodeLen() * $this->moduleSize - $this->getBarcodeLen() * $this->moduleSize / 4 - $textWidth / 2 + 2 * $margin, $this->height - $this->fontSize / 2 + $margin, $charsC, $black);
     }
     return $im2;
 }