Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Aspose.BarCode for PHP via Java
<?php
// create barcode generator
$generator = new BarcodeGenerator(EncodeTypes::CODE_128);
// set caption
$generator->getParameters()->getCaptionAbove()->setText("BARCODE's CAPTION");
// set visibility
$generator->getParameters()->getCaptionAbove()->setVisible(true);
// set font family
$generator->getParameters()->getCaptionAbove()->getFont()->setStyle(FontStyle::ITALIC);
// set font size
$generator->getParameters()->getCaptionAbove()->getFont()->getSize()->setPoint(10);
// set image resolution
$generator->getParameters()->setResolution(200);
// generate and save barcode
$save_path = "barcodes/generate-barcode-caption.bmp";
$generator->saveImageFormat($save_path, "BMP");
?>
<?php
// create barcode generator
$generator = new BarcodeGenerator(EncodeTypes::CODE_39_STANDARD, "12367891011");
// set barcode back color
$generator->getParameters()->setBackColor("#FF0000");
// set barcode fore color
$generator->getParameters()->getBarcode()->setForeColor("#FA00AA");
// set barcode border color
$generator->getParameters()->getBorder()->setColor("#AA00BB");
// set image resolution
$generator->getParameters()->setResolution(200);
// generate and save barcode
$generator->save("barcodes/generate-barcode-customize-apprearance.png");
?>
<?php
// set barcode encode type as QR
$encodeType = EncodeTypes::QR;
// create barcode generator
$generator = new BarcodeGenerator($encodeType, '01234567');
// set image resolution
$generator->getParameters()->setResolution(400);
// generate QR code and save
$generator->save("barcodes/generate-QR-code.png");
?>
<?php
// create barcode generator
$generator = new BarcodeGenerator(EncodeTypes::CODE_128, "12367891011");
// set image resolution
$generator->getParameters()->setResolution(200);
// generate and save barcode
$generator->save("barcodes/generate-barcode.png");
?>
<?php
try
{
$file_name = "barcode.png";
$reader = new BarcodeReader(loadImageByName("barcodes/",$file_name), DecodeType::CODE_128);
while($reader->read())
{
print("Code Type : ".$reader->getCodeTypeName());
print("\n");
print("Code Text : ".$reader->getCodeText(false));
}
$reader->close();
}
catch (BarcodeException $e)
{
print($e->getMessage());
}
?>
<?php
$file_name = "barcodes/barcode.png";
print(file_exists($file_name));
$reader = new BarcodeReader($file_name);
while ($reader->read())
{
print($reader->getCodeText(false));
print("\n");
print($reader->getCodeTypeName());
}
$reader->close();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.