/**
  * Metodo para gerar o arquivo
  * @param string $valor
  * @param string $filename	caminho onde sera salvo o arquivo e nome mais extensao
  * @since 18/12/2012
  */
 public function gerar($valor, $filename, $font1, $marg, $x1, $y1, $height1, $width1, $angle1, $x2, $y2, $x3, $y3)
 {
     $fontSize = $font1;
     // GD1 in px ; GD2 in point
     $marge = $marg;
     // between barcode and hri in pixel
     $x = $x1;
     // barcode center
     $y = $y1;
     // barcode center
     $height = $height1;
     // barcode height in 1D ; module size in 2D
     $width = $width1;
     // barcode height in 1D ; not use in 2D
     $angle = $angle1;
     // rotation in degrees : nb : non horizontable barcode might not be usable because of pixelisation
     $code = $valor;
     // barcode, of course ;)
     $type = 'code128';
     // -------------------------------------------------- //
     //            ALLOCATE GD RESSOURCE
     // -------------------------------------------------- //
     $im = imagecreatetruecolor($x2, $y2);
     $black = ImageColorAllocate($im, 0x0, 0x0, 0x0);
     $white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
     $red = ImageColorAllocate($im, 0xff, 0x0, 0x0);
     $blue = ImageColorAllocate($im, 0x0, 0x0, 0xff);
     imagefilledrectangle($im, 0, 0, $x3, $y3, $white);
     // -------------------------------------------------- //
     //                      BARCODE
     // -------------------------------------------------- //
     $data = Barcode::gd($im, $black, $x, $y, $angle, $type, array('code' => $code), $width, $height);
     // -------------------------------------------------- //
     //                        HRI						  //
     // -------------------------------------------------- //
     if (isset($font)) {
         $box = imagettfbbox($fontSize, 0, $font, $data['hri']);
         $len = $box[2] - $box[0];
         Barcode::rotate(-$len / 2, $data['height'] / 2 + $fontSize + $marge, $angle, $xt, $yt);
         imagettftext($im, $fontSize, $angle, $x + $xt, $y + $yt, $blue, $font, $data['hri']);
     }
     //header('Content-type: image/gif');
     imagegif($im, $filename);
     //imagegif($image,$this->file);
     imagedestroy($im);
 }
Esempio n. 2
0
function DrawBarCode($params, $text, $fx, $fy)
{
    if (!isset($params['image'])) {
        return;
    }
    $img = $params['image'];
    $w = imagesx($img);
    $h = imagesy($img);
    if (isset($params['color'])) {
        $color = $params['color'];
    } else {
        $color = ImageColorAllocate($img, 0x0, 0x0, 0x0);
    }
    if (isset($params['angle'])) {
        $angle = $params['angle'];
    } else {
        $angle = 0.0;
    }
    if (isset($params['height'])) {
        $barheight = $params['height'];
    } else {
        $barheight = 0.2 * $h;
    }
    // about 1/5 of the image size.
    if (isset($params['width'])) {
        $barwidth = $params['width'];
    } else {
        $barwidth = $w / 200;
    }
    // Just a guess.  Works out to be about 3px.
    $type = 'code128';
    $x0 = intval($fx * $w);
    $y0 = intval($fy * $h);
    $data = Barcode::gd($img, $color, $x0, $y0, $angle, $type, array('code' => $text), $barwidth, $barheight);
}
Esempio n. 3
0
    // obtiene los valores de las varibles
    // crea las variables y les asigna el valor
    for ($i = 0; $i < $numero; $i++) {
        ${$tags}[$i] = $valores[$i];
    }
    // Agrega ademas las variables de sesion
    if (!empty($_SESSION)) {
        extract($_SESSION);
    }
}
$x = $AnchoImagen / 2;
// Centro X del codigo en la imagen
$y = $AltoImagen / 2;
// Centro Y del codigo dentro de la imagen
if ($Tipo != "datamatrix") {
    $height = $AltoCodigo;
    // Alto del codigo en 1D o tamano de modulo en 2D
    $width = $AnchoCodigo;
    // Ancho del codigo en 1D ; no usar en 2D
}
//Separa recursos de trabajo en GD
$im = imagecreatetruecolor($AnchoImagen, $AltoImagen);
$black = ImageColorAllocate($im, 0x0, 0x0, 0x0);
$white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
imagefilledrectangle($im, 0, 0, $AnchoImagen, $AltoImagen, $white);
//Llama el metodo para generar el codigo
$data = Barcode::gd($im, $black, $x, $y, 0, $Tipo, array('code' => $Cadena), $width, $height);
//Genera la imagen
header('Content-type: image/gif');
imagegif($im);
imagedestroy($im);
Esempio n. 4
0
function generate_barcode($type, $data)
{
    require_once PT::$ABSPATH . "/lib/barcode-master/php-barcode.php";
    $font = "./lib/barcode-master/NOTTB___.TTF";
    $fontSize = 10;
    // GD1 in px ; GD2 in point
    $marge = 2;
    // between barcode and hri in pixel
    $y = 25;
    // barcode center
    $height = 50;
    // barcode height in 1D ; module size in 2D
    $width = 2;
    // barcode height in 1D ; not use in 2D
    $angle = 0;
    // rotation in degrees : nb : non horizontable barcode might not be usable because of pixelisation
    $code = $data;
    $type = $type;
    // Precompute digits to set image width
    switch ($type) {
        case 'std25':
        case 'int25':
            $digit = \BarcodeI25::getDigit($code, $crc, $type);
            break;
        case 'ean8':
        case 'ean13':
            $digit = \BarcodeEAN::getDigit($code, $type);
            break;
        case 'upc':
            $digit = \BarcodeUPC::getDigit($code);
            break;
        case 'code11':
            $digit = \Barcode11::getDigit($code);
            break;
        case 'code39':
            $digit = \Barcode39::getDigit($code);
            break;
        case 'code93':
            $digit = \Barcode93::getDigit($code, $crc);
            break;
        case 'code128':
            $digit = \Barcode128::getDigit($code);
            break;
        case 'codabar':
            $digit = \BarcodeCodabar::getDigit($code);
            break;
        case 'msi':
            $digit = \BarcodeMSI::getDigit($code, $crc);
            break;
        case 'datamatrix':
            $digit = \BarcodeDatamatrix::getDigit($code, $rect);
            break;
    }
    $imgWidth = strlen($digit) * $width;
    $x = $imgWidth / 2;
    $im = imagecreatetruecolor($imgWidth, 62);
    $black = ImageColorAllocate($im, 0x0, 0x0, 0x0);
    $white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
    $red = ImageColorAllocate($im, 0xff, 0x0, 0x0);
    $blue = ImageColorAllocate($im, 0x0, 0x0, 0xff);
    imagefilledrectangle($im, 0, 0, $imgWidth, 62, $white);
    $data = \Barcode::gd($im, $black, $x, $y, $angle, $type, array('code' => $code), $width, $height);
    if (isset($font)) {
        $box = imagettfbbox($fontSize, 0, $font, $data['hri']);
        $len = $box[2] - $box[0];
        \Barcode::rotate(-$len / 2, $data['height'] / 2 + $fontSize + $marge, $angle, $xt, $yt);
        imagettftext($im, $fontSize, $angle, $x + $xt, $y + $yt, $black, $font, $data['hri']);
    }
    header('Content-type: image/gif');
    imagegif($im);
    imagedestroy($im);
}
Esempio n. 5
0
} else {
    $im = imagecreatetruecolor(200, 150);
}
$black = ImageColorAllocate($im, 0x0, 0x0, 0x0);
$white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
$red = ImageColorAllocate($im, 0xff, 0x0, 0x0);
$blue = ImageColorAllocate($im, 0x0, 0x0, 0xff);
if (isset($huge)) {
    imagefilledrectangle($im, 0, 0, 800, 600, $white);
} else {
    imagefilledrectangle($im, 0, 0, 200, 150, $white);
}
// -------------------------------------------------- //
// BARCODE
// -------------------------------------------------- //
$data = Barcode::gd($im, $black, $x, $y, $angle, $type, array('code' => $code), $width, $height);
// -------------------------------------------------- //
// HRI
// -------------------------------------------------- //
if (isset($font)) {
    $box = imagettfbbox($fontSize, 0, $font, $data['hri']);
    $len = $box[2] - $box[0];
    Barcode::rotate(-$len / 2, $data['height'] / 2 + $fontSize + $marge, $angle, $xt, $yt);
    imagettftext($im, $fontSize, $angle, $x + $xt, $y + $yt, $blue, $font, $data['hri']);
}
// -------------------------------------------------- //
// ROTATE
// -------------------------------------------------- //
// Beware ! the rotate function should be use only with right angle
// Remove the comment below to see a non right rotation
/**
Esempio n. 6
0
 /**
  * 	standard 2 of 5 (std25)
  * 	interleaved 2 of 5 (int25)
  * 	ean 8 (ean8)
  * 	ean 13 (ean13)
  * 	upc (upc)
  * 	code 11 (code11)
  * 	code 39 (code39)
  * 	code 93 (code93)
  * 	code 128 (code128)
  * 	codabar (codabar)
  * 	msi (msi)
  * 	datamatrix (datamatrix)
  **/
 public function dataImage($type, $code, $ops)
 {
     if (is_array($code)) {
         $code = $this->setCodeData($code);
     }
     // -------------------------------------------------- //
     //            ALLOCATE GD RESSOURCE
     // -------------------------------------------------- //
     $im = imagecreatetruecolor($this->imageWidth, $this->imageHeigth);
     $black = ImageColorAllocate($im, 0x0, 0x0, 0x0);
     $white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
     $red = ImageColorAllocate($im, 0xff, 0x0, 0x0);
     $blue = ImageColorAllocate($im, 0x0, 0x0, 0xff);
     imagefilledrectangle($im, 0, 0, $this->imageWidth, $this->imageHeigth, $white);
     // -------------------------------------------------- //
     //                      BARCODE
     // -------------------------------------------------- //
     $data = Barcode::gd($im, $black, $this->x, $this->y, $this->angle, $type, array('code' => $code), $this->width, $this->height);
     $code = implode(' ', str_split($code));
     $fw = imagefontwidth($this->fontSize);
     // width of a character
     $l = strlen($code);
     // number of characters
     $tw = $l * $fw;
     // text width
     $iw = imagesx($im);
     // image width
     $xpos = ($iw - $tw) / 2;
     imagestring($im, $this->fontSize, $xpos, $this->y + 60, $code, $black);
     // -------------------------------------------------- //
     //                        HRI
     // -------------------------------------------------- //
     if (isset($this->font)) {
         $box = imagettfbbox($this->fontSize, 0, $this->font, $data['hri']);
         $len = $box[2] - $box[0];
         Barcode::rotate(-$len / 2, $data['height'] / 2 + $this->fontSize + $this->marge, $this->angle, $xt, $yt);
         imagettftext($im, $this->fontSize, $this->angle, $this->x + $xt, $this->y + $yt, $blue, $this->font, $data['hri']);
     }
     // -------------------------------------------------- //
     //                    MIDDLE AXE
     // -------------------------------------------------- //
     //imageline($im, $this->x, 0, $this->x, 250, $red);
     //imageline($im, 0, $this->y, 250, $this->y, $red);
     // -------------------------------------------------- //
     //                  BARCODE BOUNDARIES
     // -------------------------------------------------- //
     for ($i = 1; $i < 5; $i++) {
         // $this->__drawCross($im, $blue, $data['p'.$i]['x'], $data['p'.$i]['y']);
     }
     // -------------------------------------------------- //
     //                    GENERATE
     // -------------------------------------------------- //
     // header('Content-type: image/gif');
     $temp = tmpfile();
     $metaDatas = stream_get_meta_data($temp);
     $tmpFilename = $metaDatas['uri'];
     imagepng($im, $tmpFilename);
     $fcon = file_get_contents($tmpFilename);
     imagedestroy($im);
     $media = array('type' => 'jpg', 'file' => $fcon);
     $pxiimg = $this->PxHtml->imageData($media, $ops);
     return $pxiimg;
 }
Esempio n. 7
0
File: Barcode.php Progetto: cicb/tpc
 public static function getCodigo($code)
 {
     $im = imagecreatetruecolor(200, 50);
     $black = ImageColorAllocate($im, 0x0, 0x0, 0x0);
     $white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
     //imagefilledrectangle($im, 0, 0, 300, 300, $white);
     imagefill($im, 0, 0, $white);
     $data = Barcode::gd($im, $black, 100, 25, 0, 'ean13', array('code' => $code), 2, 40);
     //$data =Barcode::fpdf($im, $black, 125, 125, 0, 'ean13',   array('code'=>$code), 2, 50);
     ob_start();
     imagepng($im);
     $image_data = ob_get_contents();
     ob_end_clean();
     imagedestroy($im);
     echo '<img src="data:image/png;base64,' . base64_encode($image_data) . '" />';
 }
function getBarCodePicture(&$assetOf)
{
    dol_include_once('/asset/php_barcode/php-barcode.php');
    $code = $assetOf->numero;
    $fontSize = 10;
    // GD1 in px ; GD2 in point
    $marge = 10;
    // between barcode and hri in pixel
    $x = 145;
    // barcode center
    $y = 50;
    // barcode center
    $height = 50;
    // barcode height in 1D ; module size in 2D
    $width = 2;
    // barcode height in 1D ; not use in 2D
    $angle = 0;
    // rotation in degrees : nb : non horizontable barcode might not be usable because of pixelisation
    $type = 'code128';
    $im = imagecreatetruecolor(300, 100);
    $black = ImageColorAllocate($im, 0x0, 0x0, 0x0);
    $white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
    $red = ImageColorAllocate($im, 0xff, 0x0, 0x0);
    $blue = ImageColorAllocate($im, 0x0, 0x0, 0xff);
    imagefilledrectangle($im, 0, 0, 300, 300, $white);
    $data = Barcode::gd($im, $black, $x, $y, $angle, $type, array('code' => $code), $width, $height);
    if (isset($font)) {
        $box = imagettfbbox($fontSize, 0, $font, $data['hri']);
        $len = $box[2] - $box[0];
        Barcode::rotate(-$len / 2, $data['height'] / 2 + $fontSize + $marge, $angle, $xt, $yt);
        imagettftext($im, $fontSize, $angle, $x + $xt, $y + $yt, $blue, $font, $data['hri']);
    }
    $tmpfname = tempnam(sys_get_temp_dir(), 'barcode_pic');
    imagepng($im, $tmpfname);
    imagedestroy($im);
    return $tmpfname;
}
Esempio n. 9
0
                if ($class != -1) {
                    $classe = $classi[$class]["nome"];
                }
                $tot = explode(" ", $result["nome"]);
                $nome = "";
                for ($i = 0; $i < count($tot); $i++) {
                    $nome .= $tot[$i];
                    if ($i == 0) {
                        $nome .= ";";
                    } else {
                        if ($i != count($tot) - 1) {
                            $nome .= " ";
                        }
                    }
                }
                $data = Barcode::gd($im, $black, $x, $y, $angle, $type, array('code' => $eans[ricerca($eans, $result["id"], "persona")]["ean"]), $width, $height);
                file_put_contents("barcode.txt", $data['hri'] . ";" . $nome . ";" . $classe . "\n", FILE_APPEND | LOCK_EX);
            }
        }
    }
} else {
    class BarcodeFPDF extends FPDF
    {
        public $h;
        public $k;
        public function __construct($orientation = 'P', $unit = 'mm', $size = 'A4')
        {
            parent::__construct($orientation, $unit, $size);
            $this->h = parent::GetPageHeight();
            $this->k = 1;
        }
Esempio n. 10
-12
function generate_barcode($first, $code, $terminal)
{
    if ($first) {
        $len = strlen($code);
        if ($len > 9) {
            $code = substr($code, $len - 9);
            $len = 9;
        }
        for ($i = 0; $i < 9 - $len; $i++) {
            $code = '0' . $code;
        }
        $code = '1' . $terminal . $code;
    }
    // -------------------------------------------------- //
    //                  PROPERTIES
    // -------------------------------------------------- //
    // download a ttf font here for example : http://www.dafont.com/fr/nottke.font
    //$font     = './NOTTB___.TTF';
    // - -
    $folio = BarcodeEAN::compute($code, 'ean13');
    $fontSize = 10;
    // GD1 in px ; GD2 in point
    $marge = 10;
    // between barcode and hri in pixel
    $x = 110;
    // barcode center
    $y = 40;
    // barcode center
    $height = 50;
    // barcode height in 1D ; module size in 2D
    $width = 2;
    // barcode height in 1D ; not use in 2D
    $angle = 0;
    // rotation in degrees : nb : non horizontable barcode might not be usable because of pixelisation
    //$code     = '750000000001'; // barcode, of course ;)
    $type = 'ean13';
    // -------------------------------------------------- //
    //                    USEFUL
    // -------------------------------------------------- //
    /*function drawCross($im, $color, $x, $y){
        imageline($im, $x - 10, $y, $x + 10, $y, $color);
        imageline($im, $x, $y- 10, $x, $y + 10, $color);
      }*/
    // -------------------------------------------------- //
    //            ALLOCATE GD RESSOURCE
    // -------------------------------------------------- //
    $im = imagecreatetruecolor(220, 80);
    $black = ImageColorAllocate($im, 0x0, 0x0, 0x0);
    $white = ImageColorAllocate($im, 0xff, 0xff, 0xff);
    $red = ImageColorAllocate($im, 0xff, 0x0, 0x0);
    $blue = ImageColorAllocate($im, 0x0, 0x0, 0xff);
    imagefilledrectangle($im, 0, 0, 220, 80, $white);
    // -------------------------------------------------- //
    //                      BARCODE
    // -------------------------------------------------- //
    $data = Barcode::gd($im, $black, $x, $y, $angle, $type, array('code' => $code), $width, $height);
    // -------------------------------------------------- //
    //                        HRI
    // -------------------------------------------------- //
    if (isset($font)) {
        $box = imagettfbbox($fontSize, 0, $font, $data['hri']);
        $len = $box[2] - $box[0];
        Barcode::rotate(-$len / 2, $data['height'] / 2 + $fontSize + $marge, $angle, $xt, $yt);
        imagettftext($im, $fontSize, $angle, $x + $xt, $y + $yt, $blue, $font, $data['hri']);
    }
    // -------------------------------------------------- //
    //                     ROTATE
    // -------------------------------------------------- //
    // Beware ! the rotate function should be use only with right angle
    // Remove the comment below to see a non right rotation
    /** /
        $rot = imagerotate($im, 45, $white);
        imagedestroy($im);
        $im     = imagecreatetruecolor(900, 300);
        $black  = ImageColorAllocate($im,0x00,0x00,0x00);
        $white  = ImageColorAllocate($im,0xff,0xff,0xff);
        $red    = ImageColorAllocate($im,0xff,0x00,0x00);
        $blue   = ImageColorAllocate($im,0x00,0x00,0xff);
        imagefilledrectangle($im, 0, 0, 900, 300, $white);
        
        // Barcode rotation : 90�
        $angle = 90;
        $data = Barcode::gd($im, $black, $x, $y, $angle, $type, array('code'=>$code), $width, $height);
        Barcode::rotate(-$len / 2, ($data['height'] / 2) + $fontSize + $marge, $angle, $xt, $yt);
        imagettftext($im, $fontSize, $angle, $x + $xt, $y + $yt, $blue, $font, $data['hri']);
        imagettftext($im, 10, 0, 60, 290, $black, $font, 'BARCODE ROTATION : 90�');
        
        // barcode rotation : 135
        $angle = 135;
        Barcode::gd($im, $black, $x+300, $y, $angle, $type, array('code'=>$code), $width, $height);
        Barcode::rotate(-$len / 2, ($data['height'] / 2) + $fontSize + $marge, $angle, $xt, $yt);
        imagettftext($im, $fontSize, $angle, $x + 300 + $xt, $y + $yt, $blue, $font, $data['hri']);
        imagettftext($im, 10, 0, 360, 290, $black, $font, 'BARCODE ROTATION : 135�');
        
        // last one : image rotation
        imagecopy($im, $rot, 580, -50, 0, 0, 300, 300);
        imagerectangle($im, 0, 0, 299, 299, $black);
        imagerectangle($im, 299, 0, 599, 299, $black);
        imagerectangle($im, 599, 0, 899, 299, $black);
        imagettftext($im, 10, 0, 690, 290, $black, $font, 'IMAGE ROTATION');
        /**/
    // -------------------------------------------------- //
    //                    MIDDLE AXE
    // -------------------------------------------------- //
    /*imageline($im, $x, 0, $x, 250, $red);
      imageline($im, 0, $y, 250, $y, $red);*/
    // -------------------------------------------------- //
    //                  BARCODE BOUNDARIES
    // -------------------------------------------------- //
    /*for($i=1; $i<5; $i++){
        drawCross($im, $blue, $data['p'.$i]['x'], $data['p'.$i]['y']);
      }*/
    // -------------------------------------------------- //
    //                    GENERATE
    // -------------------------------------------------- //
    header('Content-type: image/png');
    imagepng($im, $folio . ".png");
    imagedestroy($im);
    return $folio;
}