72 lines
2.5 KiB
PHP
72 lines
2.5 KiB
PHP
<?php
|
|
// Including all required classes
|
|
require('barcode_php8/class/BCGFont.php');
|
|
require('barcode_php8/class/BCGColor.php');
|
|
require('barcode_php8/class/BCGDrawing.php');
|
|
|
|
// Including the barcode technology
|
|
include('barcode_php8/class/BCGcode39.barcode.php');
|
|
|
|
|
|
function barcode_BCGcode39_saveImage ($filename, $systemPath = "..", $text, $scale, $thickness, $imgWidth, $imgheight) {
|
|
$retVal = "";
|
|
if ($filename != "") :
|
|
if ($scale == "") : $scale = "2"; endif;
|
|
if ($thickness == "") : $thickness = "30"; endif;
|
|
|
|
// MC 2024-10-16
|
|
// ----
|
|
echo "filename = " . $filename . "<br>";
|
|
echo "systemPath = " . $systemPath . "<br>";
|
|
echo "text = " . $text . "<br>";
|
|
/*
|
|
$dirName = dirname(__FILE__);
|
|
$dirName = str_replace("\\", "/", $dirName);
|
|
$lastSlashPos = strrpos($dirName,"/");
|
|
$path = substr($dirName, 0, $lastSlashPos);
|
|
// echo $path; die();
|
|
$font = new BCGFont($path . '/include/arial.ttf', 18);
|
|
*/
|
|
// ----
|
|
$font = new BCGFont('./barcode_php8/class/font/Arial.ttf', 18);
|
|
die();
|
|
// The arguments are R, G, B for color.
|
|
$color_black = new BCGColor(0, 0, 0);
|
|
$color_white = new BCGColor(255, 255, 255);
|
|
|
|
$code = new BCGcode39();
|
|
$code->setScale($scale); // Resolution
|
|
$code->setThickness($thickness); // Thickness
|
|
$code->setForegroundColor($color_black); // Color of bars
|
|
$code->setBackgroundColor($color_white); // Color of spaces
|
|
$code->setFont($font); // Font (or 0)
|
|
$code->parse($text); // Text
|
|
|
|
/* Here is the list of the arguments
|
|
1 - Filename (empty : display on screen)
|
|
2 - Background color */
|
|
$drawing = new BCGDrawing($filename, $color_white);
|
|
$drawing->setBarcode($code);
|
|
$drawing->draw();
|
|
|
|
// Header that says it is an image (remove it if you save the barcode to a file)
|
|
if (false) :
|
|
header('Content-Type: image/png');
|
|
endif;
|
|
|
|
// Draw (or save) the image into PNG format.
|
|
$drawing->finish($drawing->IMG_FORMAT_PNG);
|
|
|
|
// Manual scaling of the displayed image
|
|
if ($imgWidth != "") : $imgWidth = " width=\"" . $imgWidth . "\" "; endif;
|
|
if ($imgheight != "") : $imgheight = " height=\"" . $imgheight . "\" "; endif;
|
|
|
|
if ($systemPath == "..") :
|
|
$retVal = "<img src=\"" . $filename . "\" border=\"0\"" . $imgWidth . $imgheight . ">";
|
|
else :
|
|
$retVal = "<img src=\"<PATH_ABS>" . $filename . "</PATH_ABS>\" border=\"0\"" . $imgWidth . $imgheight . ">";
|
|
endif;
|
|
endif;
|
|
return $retVal;
|
|
}
|
|
?>
|