Exemplo n.º 1
0
 private static function _draw($call, $res, $color, $x, $y, $angle, $type, $datas, $width, $height)
 {
     $digit = '';
     $hri = '';
     $code = '';
     $crc = true;
     $rect = false;
     $b2d = false;
     if (is_array($datas)) {
         foreach (array('code' => '', 'crc' => true, 'rect' => false) as $v => $def) {
             ${$v} = isset($datas[$v]) ? $datas[$v] : $def;
         }
         $code = $code;
     } else {
         $code = $datas;
     }
     if ($code == '') {
         return false;
     }
     $code = (string) $code;
     $type = strtolower($type);
     switch ($type) {
         case 'std25':
         case 'int25':
             $digit = BarcodeI25::getDigit($code, $crc, $type);
             $hri = BarcodeI25::compute($code, $crc, $type);
             break;
         case 'ean8':
         case 'ean13':
             $digit = BarcodeEAN::getDigit($code, $type);
             $hri = BarcodeEAN::compute($code, $type);
             break;
         case 'upc':
             $digit = BarcodeUPC::getDigit($code);
             $hri = BarcodeUPC::compute($code);
             break;
         case 'code11':
             $digit = Barcode11::getDigit($code);
             $hri = $code;
             break;
         case 'code39':
             $digit = Barcode39::getDigit($code);
             $hri = $code;
             break;
         case 'code93':
             $digit = Barcode93::getDigit($code, $crc);
             $hri = $code;
             break;
         case 'code128':
             $digit = Barcode128::getDigit($code);
             $hri = $code;
             break;
         case 'codabar':
             $digit = BarcodeCodabar::getDigit($code);
             $hri = $code;
             break;
         case 'msi':
             $digit = BarcodeMSI::getDigit($code, $crc);
             $hri = BarcodeMSI::compute($code, $crc);
             break;
         case 'datamatrix':
             $digit = BarcodeDatamatrix::getDigit($code, $rect);
             $hri = $code;
             $b2d = true;
             break;
     }
     if ($digit == '') {
         return false;
     }
     if ($b2d) {
         $width = is_null($width) ? 5 : $width;
         $height = $width;
     } else {
         $width = is_null($width) ? 1 : $width;
         $height = is_null($height) ? 50 : $height;
         $digit = self::bitStringTo2DArray($digit);
     }
     if ($call == 'gd') {
         $result = self::digitToGDRenderer($res, $color, $x, $y, $angle, $width, $height, $digit);
     } else {
         if ($call == 'fpdf') {
             $result = self::digitToFPDFRenderer($res, $color, $x, $y, $angle, $width, $height, $digit);
         }
     }
     $result['hri'] = $hri;
     return $result;
 }
Exemplo n.º 2
0
 public static function raw($type, $datas)
 {
     $digit = '';
     $hri = '';
     $code = '';
     $crc = true;
     $rect = false;
     if (is_array($datas)) {
         foreach (array('code' => '', 'crc' => true, 'rect' => false) as $v => $def) {
             ${$v} = isset($datas[$v]) ? $datas[$v] : $def;
         }
         $code = $code;
     } else {
         $code = $datas;
     }
     if ($code == '') {
         return false;
     }
     $code = (string) $code;
     $type = strtolower($type);
     switch ($type) {
         case 'std25':
         case 'int25':
             $digit = BarcodeI25::getDigit($code, $crc, $type);
             $hri = BarcodeI25::compute($code, $crc, $type);
             break;
         case 'ean8':
         case 'ean13':
             $digit = BarcodeEAN::getDigit($code, $type);
             $hri = BarcodeEAN::compute($code, $type);
             break;
         case 'upc':
             $digit = BarcodeUPC::getDigit($code);
             $hri = BarcodeUPC::compute($code);
             break;
         case 'code11':
             $digit = Barcode11::getDigit($code);
             $hri = $code;
             break;
         case 'code39':
             $digit = Barcode39::getDigit($code);
             $hri = $code;
             break;
         case 'code93':
             $digit = Barcode93::getDigit($code, $crc);
             $hri = $code;
             break;
         case 'code128':
             $digit = Barcode128::getDigit($code);
             $hri = $code;
             break;
         case 'codabar':
             $digit = BarcodeCodabar::getDigit($code);
             $hri = $code;
             break;
         case 'msi':
             $digit = BarcodeMSI::getDigit($code, $crc);
             $hri = BarcodeMSI::compute($code, $crc);
             break;
         case 'datamatrix':
             $digit = BarcodeDatamatrix::getDigit($code, $rect);
             $hri = $code;
             break;
     }
     return array($digit, $hri);
 }
Exemplo n.º 3
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);
}