Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php barcode generator

//In this PHP code, the tc-lib-barcode library autoload file is included at the beginning. Then the form data is received by using the POST request data array. The MFG and EXP dates are converted into a timestamp.

//Then, the product MRP and MFG/EXP timestamps are bundled into a string format. This formatted product data will be passed to the getBarcodeObj. This function will return barcode object based on the type specified.

<?php
if (! empty($_POST["generate"])) {
    require ('tc-lib-barcode/vendor/autoload.php');
    $barcode = new ComTecnickBarcodeBarcode();
    $targetPath = "barcode/";
    
    if (! is_dir($targetPath)) {
        mkdir($targetPath, 0777, true);
    }
    $MRP = $_POST["mrp"];
    $MFGDate = strtotime($_POST["mfg_date"]);
    $EXPDate = strtotime($_POST["exp_date"]);
    $productData = "098{$MRP}10{$MFGDate}55{$EXPDate}";
    $barcode = new ComTecnickBarcodeBarcode();
    $bobj = $barcode->getBarcodeObj('C128C', "{$productData}", 450, 70, 'black', array(
        0,
        0,
        0,
        0
    ));
    
    $imageData = $bobj->getPngData();
    $timestamp = time();
    
    file_put_contents($targetPath . $timestamp . '.png', $imageData);
    ?>
<div class="result-heading">Output:</div>
<img src="<?php echo $targetPath . $timestamp ; ?>.png">
<?php
}
?>
 
PREVIOUS NEXT
Tagged: #php #barcode #generator
ADD COMMENT
Topic
Name
3+2 =