/** * 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); }
} else { $marge = 5; // between barcode and hri in pixel $x = 30; // barcode center $y = 120; // barcode center $height = 40; // barcode height in 1D ; module size in 2D $width = 1; // barcode height in 1D ; not use in 2D } // -------------------------------------------------- // // ALLOCATE FPDF RESSOURCE // -------------------------------------------------- // $pdf = new eFPDF('P', 'mm', array(102, 252)); // set the orentation, unit of measure and size of the page $pdf->AddPage(); // -------------------------------------------------- // // BARCODE // -------------------------------------------------- // $data = Barcode::fpdf($pdf, $black, $x, $y, $angle, $type, array('code' => $code), $width, $height); $pdf->SetFont('Arial', 'B', $fontSize); $pdf->SetTextColor(0, 0, 0); $len = $pdf->GetStringWidth($data['hri']); Barcode::rotate(-$len / 2, $data['height'] / 2 + $fontSize + $marge, $angle, $xt, $yt); // -------------------------------------------------- // // OUTPUT // -------------------------------------------------- // $pdf->TextWithRotation($x + $xt, $y + $yt, $data['hri'], $angle); $pdf->Output();
public function addBarcode($code) { $fontSize = 2.4; $marge = 1; // between barcode and hri in pixel $x = $this->GetX() + 45; // barcode center $y = $this->GetY() + 6; // barcode center $height = 9; // barcode height in 1D ; module size in 2D $width = 0.37; // 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 = 'code39'; $black = '000000'; // color in hexa //$this->SetFont('Arial','B',$fontSize); $data = Barcode::fpdf($this, $black, $x, $y, $angle, $type, array('code' => $code), $width, $height); //$this->SetFont('Arial','B',$fontSize); //$this->SetTextColor(0, 0, 0); $len = $this->GetStringWidth($data['hri']); Barcode::rotate(-$len / 2, $data['height'] / 2 + $fontSize + $marge, $angle, $xt, $yt); $this->TextWithRotation($x + $xt, $y + $yt, $data['hri'], $angle); $this->setLineWidth(0.12); }
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); }
/** * 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; }
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; }
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; }