Example #1
0
 public static function Barcode39($barcode, $width, $height, $quality, $text, $path)
 {
     $im = ImageCreate($width, $height) or die("Cannot Initialize new GD image stream");
     $White = ImageColorAllocate($im, 255, 255, 255);
     $Black = ImageColorAllocate($im, 0, 0, 0);
     //ImageColorTransparent ($im, $White);
     ImageInterLace($im, 1);
     $NarrowRatio = 20;
     $WideRatio = 55;
     $QuietRatio = 35;
     $nChars = (strlen($barcode) + 2) * (6 * $NarrowRatio + 3 * $WideRatio + $QuietRatio);
     $Pixels = $width / $nChars;
     $NarrowBar = (int) (20 * $Pixels);
     $WideBar = (int) (55 * $Pixels);
     $QuietBar = (int) (35 * $Pixels);
     $ActualWidth = ($NarrowBar * 6 + $WideBar * 3 + $QuietBar) * (strlen($barcode) + 2);
     if ($NarrowBar == 0 || $NarrowBar == $WideBar || $NarrowBar == $QuietBar || $WideBar == 0 || $WideBar == $QuietBar || $QuietBar == 0) {
         ImageString($im, 1, 0, 0, "Image is too small!", $Black);
         OutputImage($im, $format, $quality);
         exit;
     }
     $CurrentBarX = (int) (($width - $ActualWidth) / 2);
     $Color = $White;
     $BarcodeFull = "*" . strtoupper($barcode) . "*";
     settype($BarcodeFull, "string");
     $FontNum = 3;
     $FontHeight = ImageFontHeight($FontNum);
     $FontWidth = ImageFontWidth($FontNum);
     if ($text != 0) {
         $CenterLoc = (int) (($width - 1) / 2) - (int) ($FontWidth * strlen($BarcodeFull) / 2);
         ImageString($im, $FontNum, $CenterLoc, $height - $FontHeight, "{$BarcodeFull}", $Black);
     } else {
         $FontHeight = -2;
     }
     for ($i = 0; $i < strlen($BarcodeFull); $i++) {
         $StripeCode = self::Code39($BarcodeFull[$i]);
         for ($n = 0; $n < 9; $n++) {
             if ($Color == $White) {
                 $Color = $Black;
             } else {
                 $Color = $White;
             }
             switch ($StripeCode[$n]) {
                 case '0':
                     ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $NarrowBar, $height - 1 - $FontHeight - 2, $Color);
                     $CurrentBarX += $NarrowBar;
                     break;
                 case '1':
                     ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $WideBar, $height - 1 - $FontHeight - 2, $Color);
                     $CurrentBarX += $WideBar;
                     break;
             }
         }
         $Color = $White;
         ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $QuietBar, $height - 1 - $FontHeight - 2, $Color);
         $CurrentBarX += $QuietBar;
     }
     return ImageJPEG($im, $path, $quality);
 }
Example #2
0
function Barcode39 ($barcode, $width, $height, $quality, $format, $text)
{
switch ($format)
{
default:
$format = "JPEG";
case "JPEG": 
header ("Content-type: image/jpeg");
break;
case "PNG":
header ("Content-type: image/png");
break;
case "GIF":
header ("Content-type: image/gif");
break;
}


$im = ImageCreate ($width, $height)
or die ("Cannot Initialize new GD image stream");
$White = ImageColorAllocate ($im, 255, 255, 255);
$Black = ImageColorAllocate ($im, 0, 0, 0);
//ImageColorTransparent ($im, $White);
ImageInterLace ($im, 1);



$NarrowRatio = 20;
$WideRatio = 55;
$QuietRatio = 35;


$nChars = (strlen($barcode)+2) * ((6 * $NarrowRatio) + (3 * $WideRatio) + ($QuietRatio));
$Pixels = $width / $nChars;
$NarrowBar = (int)(20 * $Pixels);
$WideBar = (int)(55 * $Pixels);
$QuietBar = (int)(35 * $Pixels);


$ActualWidth = (($NarrowBar * 6) + ($WideBar*3) + $QuietBar) * (strlen ($barcode)+2);

if (($NarrowBar == 0) || ($NarrowBar == $WideBar) || ($NarrowBar == $QuietBar) || ($WideBar == 0) || ($WideBar == $QuietBar) || ($QuietBar == 0))
{
ImageString ($im, 1, 0, 0, "Image is too small!", $Black);
OutputImage ($im, $format, $quality);
exit;
}

$CurrentBarX = (int)(($width - $ActualWidth) / 2);
$Color = $White;
$BarcodeFull = "*".strtoupper ($barcode)."*";
settype ($BarcodeFull, "string");

$FontNum = 3;
$FontHeight = ImageFontHeight ($FontNum);
$FontWidth = ImageFontWidth ($FontNum);
if ($text != 0)
{
$CenterLoc = (int)(($width-1) / 2) - (int)(($FontWidth * strlen($BarcodeFull)) / 2);
ImageString ($im, $FontNum, $CenterLoc, $height-$FontHeight, "$BarcodeFull", $Black);
}
else
{
$FontHeight=-2;
}


for ($i=0; $i<strlen($BarcodeFull); $i++)
{
$StripeCode = Code39 ($BarcodeFull[$i]);


for ($n=0; $n < 9; $n++)
{
if ($Color == $White) $Color = $Black;
else $Color = $White;


switch ($StripeCode[$n])
{
case '0':
ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$NarrowBar, $height-1-$FontHeight-2, $Color);
$CurrentBarX += $NarrowBar;
break;


case '1':
ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$WideBar, $height-1-$FontHeight-2, $Color);
$CurrentBarX += $WideBar;
break;
}
}


$Color = $White;
ImageFilledRectangle ($im, $CurrentBarX, 0, $CurrentBarX+$QuietBar, $height-1-$FontHeight-2, $Color);
$CurrentBarX += $QuietBar;
}


OutputImage ($im, $format, $quality);
}
function Barcode39($barcode, $width, $height, $quality, $format, $text)
{
    switch ($format) {
        default:
            $format = "JPEG";
        case "JPEG":
            header("Content-type: image/jpeg");
            break;
        case "PNG":
            header("Content-type: image/png");
            break;
        case "GIF":
            header("Content-type: image/gif");
            break;
    }
    $height1 = 35;
    $im = ImageCreate($width, $height1) or die("Cannot Initialize new GD image stream");
    $White = ImageColorAllocate($im, 255, 255, 255);
    $Black = ImageColorAllocate($im, 0, 0, 0);
    ImageInterLace($im, 1);
    $NarrowRatio = 20;
    $WideRatio = 55;
    $QuietRatio = 35;
    $nChars = (strlen($barcode) + 2) * (6 * $NarrowRatio + 3 * $WideRatio + $QuietRatio);
    $Pixels = $width / $nChars;
    $NarrowBar = (int) (20 * $Pixels);
    $WideBar = (int) (55 * $Pixels);
    $QuietBar = (int) (35 * $Pixels);
    $ActualWidth = ($NarrowBar * 6 + $WideBar * 3 + $QuietBar) * (strlen($barcode) + 2);
    $CurrentBarX = (int) (($width - $ActualWidth) / 2);
    $Color = $White;
    $BarcodeFull = "*" . strtoupper($barcode) . "*";
    settype($BarcodeFull, "string");
    $FontNum = 3;
    $FontHeight = ImageFontHeight($FontNum);
    $FontWidth = ImageFontWidth($FontNum);
    for ($i = 0; $i < strlen($BarcodeFull); $i++) {
        $StripeCode = Code39($BarcodeFull[$i]);
        for ($n = 0; $n < 9; $n++) {
            if ($Color == $White) {
                $Color = $Black;
            } else {
                $Color = $White;
            }
            switch ($StripeCode[$n]) {
                case '0':
                    ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $NarrowBar, $height - 1 - $FontHeight - 2, $Color);
                    $CurrentBarX += $NarrowBar;
                    break;
                case '1':
                    ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $WideBar, $height - 1 - $FontHeight - 2, $Color);
                    $CurrentBarX += $WideBar;
                    break;
            }
        }
        $Color = $White;
        ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $QuietBar, $height - 1 - $FontHeight - 2, $Color);
        $CurrentBarX += $QuietBar;
    }
    OutputImage($im, $format, $quality);
}
Example #4
0
function Barcode39($barcode, $width, $height, $quality, $format, $text)
{
    switch ($format) {
        default:
            $format = 'JPEG';
        case 'JPEG':
            header('Content-type: image/jpeg');
            break;
        case 'PNG':
            header('Content-type: image/png');
            break;
        case 'GIF':
            header('Content-type: image/gif');
            break;
    }
    $im = ImageCreate($width, $height) or die('Cannot Initialize new GD image stream');
    $White = ImageColorAllocate($im, 255, 255, 255);
    $Black = ImageColorAllocate($im, 0, 0, 0);
    //ImageColorTransparent ($im, $White);
    ImageInterLace($im, 1);
    $NarrowRatio = 20;
    $WideRatio = 55;
    $QuietRatio = 35;
    $nChars = (strlen($barcode) + 2) * (6 * $NarrowRatio + 3 * $WideRatio + $QuietRatio);
    $Pixels = $width / $nChars;
    $NarrowBar = (int) (20 * $Pixels);
    $WideBar = (int) (55 * $Pixels);
    $QuietBar = (int) (35 * $Pixels);
    $ActualWidth = ($NarrowBar * 6 + $WideBar * 3 + $QuietBar) * (strlen($barcode) + 2);
    if ($NarrowBar == 0 || $NarrowBar == $WideBar || $NarrowBar == $QuietBar || $WideBar == 0 || $WideBar == $QuietBar || $QuietBar == 0) {
        ImageString($im, 1, 0, 0, 'Image is too small!', $Black);
        OutputImage($im, $format, $quality);
        exit;
    }
    $CurrentBarX = (int) (($width - $ActualWidth) / 2);
    $Color = $White;
    $BarcodeFull = '*' . strtoupper($barcode) . '*';
    settype($BarcodeFull, 'string');
    $FontNum = 3;
    $FontHeight = ImageFontHeight($FontNum);
    $FontWidth = ImageFontWidth($FontNum);
    if ($text != '') {
        $CenterLoc = (int) ($width / 2) - (int) ($FontWidth * strlen($text) / 2);
        ImageString($im, $FontNum, $CenterLoc, $height - $FontHeight, "{$text}", $Black);
    }
    for ($i = 0; $i < strlen($BarcodeFull); $i++) {
        $StripeCode = Code39($BarcodeFull[$i]);
        for ($n = 0; $n < 9; $n++) {
            if ($Color == $White) {
                $Color = $Black;
            } else {
                $Color = $White;
            }
            switch ($StripeCode[$n]) {
                case '0':
                    ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $NarrowBar, $height - 1 - $FontHeight - 2, $Color);
                    $CurrentBarX += $NarrowBar;
                    break;
                case '1':
                    ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $WideBar, $height - 1 - $FontHeight - 2, $Color);
                    $CurrentBarX += $WideBar;
                    break;
            }
        }
        $Color = $White;
        ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $QuietBar, $height - 1 - $FontHeight - 2, $Color);
        $CurrentBarX += $QuietBar;
    }
    OutputImage($im, $format, $quality);
}
 /**
  * Generates the barcode and outputs it as header image/jpg
  *
  * @return  string
  */
 public function getBarcode()
 {
     $code = JFactory::getApplication()->input->get("code", '');
     if (empty($code)) {
         echo "No code given";
         return;
     }
     $text = 1;
     $width = 300;
     $height = 50;
     header("Content-type: image/png");
     $im = ImageCreate($width, $height) or die("Cannot Initialize new GD image stream");
     $White = ImageColorAllocate($im, 255, 255, 255);
     $Black = ImageColorAllocate($im, 0, 0, 0);
     ImageInterLace($im, 1);
     $NarrowRatio = 20;
     $WideRatio = 55;
     $QuietRatio = 35;
     $nChars = (strlen($code) + 2) * (6 * $NarrowRatio + 3 * $WideRatio + $QuietRatio);
     $Pixels = $width / $nChars;
     $NarrowBar = (int) (20 * $Pixels);
     $WideBar = (int) (55 * $Pixels);
     $QuietBar = (int) (35 * $Pixels);
     $ActualWidth = ($NarrowBar * 6 + $WideBar * 3 + $QuietBar) * (strlen($code) + 2);
     if ($NarrowBar == 0 || $NarrowBar == $WideBar || $NarrowBar == $QuietBar || $WideBar == 0 || $WideBar == $QuietBar || $QuietBar == 0) {
         ImageString($im, 1, 0, 0, "Image is too small!", $Black);
         ImagePNG($im);
         exit;
     }
     $CurrentBarX = (int) (($width - $ActualWidth) / 2);
     $Color = $White;
     $BarcodeFull = "*" . strtoupper($code) . "*";
     settype($BarcodeFull, "string");
     $FontNum = 3;
     $FontHeight = ImageFontHeight($FontNum);
     $FontWidth = ImageFontWidth($FontNum);
     if ($text != 0) {
         $CenterLoc = (int) (($width - 1) / 2) - (int) ($FontWidth * strlen($BarcodeFull) / 2);
         ImageString($im, $FontNum, $CenterLoc, $height - $FontHeight, "{$BarcodeFull}", $Black);
     } else {
         $FontHeight = -2;
     }
     for ($i = 0; $i < strlen($BarcodeFull); $i++) {
         $StripeCode = MatukioHelperUtilsBooking::getCode99($BarcodeFull[$i]);
         for ($n = 0; $n < 9; $n++) {
             if ($Color == $White) {
                 $Color = $Black;
             } else {
                 $Color = $White;
             }
             switch ($StripeCode[$n]) {
                 case '0':
                     ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $NarrowBar, $height - 1 - $FontHeight - 2, $Color);
                     $CurrentBarX += $NarrowBar;
                     break;
                 case '1':
                     ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $WideBar, $height - 1 - $FontHeight - 2, $Color);
                     $CurrentBarX += $WideBar;
                     break;
             }
         }
         $Color = $White;
         ImageFilledRectangle($im, $CurrentBarX, 0, $CurrentBarX + $QuietBar, $height - 1 - $FontHeight - 2, $Color);
         $CurrentBarX += $QuietBar;
     }
     ImagePNG($im);
     imagedestroy($im);
     jexit();
 }