Aspose.Barcode for PHP via Java Generation and Recognition API docs
|
Inherits BaseJavaClass.
Public Member Functions | |
__construct ($image, $rectangles, $decodeTypes) | |
containsAny (... $decodeTypes) | |
getFileName () | |
getTimeout () | |
setTimeout ($value) | |
getChecksumValidation () | |
setChecksumValidation ($value) | |
getStripFNC () | |
setStripFNC ($value) | |
getCustomerInformationInterpretingType () | |
setCustomerInformationInterpretingType ($value) | |
getFoundBarCodes () | |
getFoundCount () | |
readBarCodes () | |
getQualitySettings () | |
setQualitySettings (QualitySettings $value) | |
getDetectEncoding () | |
setDetectEncoding ($value) | |
setBarCodeImage ($image,... $areas) | |
setBarCodeReadType (... $types) | |
exportToXml ($xmlFile) | |
BarCodeReader encapsulates an image which may contain one or several barcodes, it then can perform ReadBarCodes operation to detect barcodes.
This sample shows how to detect Code39 and Code128 barcodes. $reader = new BarCodeReader("test.png", DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); foreach($reader->readBarCodes() as $result) { print("BarCode Type: ".$result->getCodeTypeName()); print("BarCode CodeText: ".$result->getCodeText()); }
__construct | ( | $image, | |
$rectangles, | |||
$decodeTypes | |||
) |
Initializes a new instance of the BarCodeReader
args | can take following combinations of arguments: 1) image encoded as base64 string 2) image encoded as base64 string and the array of objects by type DecodeType 3) image encoded as base64 string, array of object by type Rectangle and the array of objects by DecodeType |
PhpBarcodeException |
containsAny | ( | $decodeTypes | ) |
Determines whether any of the given decode types is included into
mixed | ...$decodeTypes Types to verify. |
exportToXml | ( | $xmlFile | ) |
Exports BarCode properties to the xml-file specified
xmlFile | The name for the file |
getChecksumValidation | ( | ) |
Enable checksum validation during recognition for 1D barcodes. Default is treated as Yes for symbologies which must contain checksum, as No where checksum only possible. Checksum never used: Codabar Checksum is possible: Code39 Standard/Extended, Standard2of5, Interleaved2of5, Matrix2of5, ItalianPost25, DeutschePostIdentcode, DeutschePostLeitcode, VIN Checksum always used: Rest symbologies This sample shows influence of ChecksumValidation on recognition quality and results
$generator = new BarcodeGenerator(EncodeTypes::EAN_13, "1234567890128"); $generator->save("test.png"); $reader = new BarCodeReader("test.png", DecodeType::EAN_13); //checksum disabled $reader->setChecksumValidation(ChecksumValidation::OFF); foreach($reader->readBarCodes() as $result) { print("BarCode CodeText: ".$result->getCodeText()); print("BarCode Value: ".$result->getExtended()->getOneD()->getValue()); print("BarCode Checksum: ".$result->getExtended()->getOneD()->getCheckSum()); } $reader = new BarCodeReader("test.png", DecodeType::EAN_13); //checksum enabled $reader->setChecksumValidation(ChecksumValidation::ON); foreach($reader->readBarCodes() as $result) { print("BarCode CodeText: ".$result->getCodeText()); print("BarCode Value: ".$result->getExtended()->getOneD()->getValue()); print("BarCode Checksum: ".$result->getExtended()->getOneD()->getCheckSum()); } The checksum validation flag.
getCustomerInformationInterpretingType | ( | ) |
Gets the Interpreting Type for the Customer Information of AustralianPost BarCode.Default is CustomerInformationInterpretingType::OTHER.
getDetectEncoding | ( | ) |
A flag which force engine to detect codetext encoding for Unicode codesets. This sample shows how to detect text encoding on the fly if DetectEncoding is enabled $image = "image.png"; $generator = new BarcodeGenerator(EncodeTypes::QR, "пїЅпїЅпїЅпїЅпїЅ")) $generator->getParameters().getBarcode()->getQR()->setCodeTextEncoding("UTF-8"); $generator->save($image, BarCodeImageFormat.getPng()); //detects encoding for Unicode codesets is enabled $reader = new BarCodeReader($image, DecodeType::QR); $reader->setDetectEncoding(true); foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText()); //detect encoding is disabled $reader = new BarCodeReader($image, DecodeType::QR); $reader->setDetectEncoding(false); foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText());
getFileName | ( | ) |
Gets file name which was assigned by user
getFoundBarCodes | ( | ) |
Gets recognized BarCodeResult array This sample shows how to read barcodes with BarCodeReader
$reader = new BarCodeReader("test.png", DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); $reader->readBarCodes(); for($i = 0; $reader->getFoundCount() > $i; ++$i) print("BarCode CodeText: ". $reader->getFoundBarCodes()[i]->getCodeText());
Value: The recognized BarCodeResult array
getFoundCount | ( | ) |
Gets recognized barcodes count
This sample shows how to read barcodes with BarCodeReader $reader = new BarCodeReader("test.png", DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); $reader->readBarCodes(); for($i = 0; $reader->getFoundCount() > $i; ++$i) print("BarCode CodeText: ".$reader->getFoundBarCodes()[i]->getCodeText()); Value: The recognized barcodes count
|
final |
QualitySettings allows to configure recognition quality and speed manually. You can quickly set up QualitySettings by embedded presets: HighPerformance, NormalQuality, HighQuality, MaxBarCodes or you can manually configure separate options. Default value of QualitySettings is NormalQuality.
This sample shows how to use QualitySettings with BarCodeReader
$reader = new BarCodeReader("test.png"); //set high performance mode $reader->setQualitySettings(QualitySettings::getHighPerformance()); foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText()); $reader = new BarCodeReader("test.png", DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); //normal quality mode is set by default foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText()); $reader = new BarCodeReader("test.png", DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); //set high performance mode $reader->setQualitySettings(QualitySettings::getHighPerformance()); //set separate options $reader->getQualitySettings()->setAllowMedianSmoothing(true); $reader->getQualitySettings()->setMedianSmoothingWindowSize(5); foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText()); QualitySettings to configure recognition quality and speed.
getStripFNC | ( | ) |
Strip FNC1, FNC2, FNC3 characters from codetext. Default value is false.
This sample shows how to strip FNC characters
$generator = new BarcodeGenerator(EncodeTypes::GS1Code128, "(02)04006664241007(37)1(400)7019590754"); $generator->save("test.png"); $reader = new BarCodeReader("test.png", DecodeType::CODE_128); //StripFNC disabled $reader->setStripFNC(false); foreach($reader->readBarCodes() as $result) { print("BarCode CodeText: ".$result->getCodeText()); } $reader = new BarCodeReader("test.png", DecodeType::CODE_128); //StripFNC enabled $reader->setStripFNC(true); foreach($reader->readBarCodes() as $result) { print("BarCode CodeText: ".$result->getCodeText()); }
getTimeout | ( | ) |
Gets the timeout of recognition process in milliseconds.
$reader = new BarCodeReader("test.png"); $reader->setTimeout(5000); foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText());
readBarCodes | ( | ) |
Reads BarCodeResult from the image. This sample shows how to read barcodes with BarCodeReader $reader = new BarCodeReader("test.png", DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText()); $reader = new BarCodeReader("test.png", DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); $reader->readBarCodes(); for($i = 0; $reader->getFoundCount() > $i; ++$i) print("BarCode CodeText: ".$reader->getFoundBarCodes()[i]->getCodeText());
|
final |
Sets bitmap image and areas for recognition. Must be called before ReadBarCodes() method. This sample shows how to detect Code39 and Code128 barcodes. $bmp = "test.png"; $reader = new BarCodeReader(); $reader->setBarCodeReadType(DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); $width, $height; list($width, $height) = getimagesize('path_to_image') $reader->setBarCodeImage($bmp, new Rectangle[] { new Rectangle(0, 0, $width, $height) }); foreach($reader->readBarCodes() as $result) { print("BarCode Type: ".$result->getCodeTypeName()); print("BarCode CodeText: ".$result->getCodeText()); }
value | The bitmap image for recognition. |
areas | areas list for recognition |
BarcodeException |
setBarCodeReadType | ( | $types | ) |
Sets SingleDecodeType type array for recognition. Must be called before readBarCodes() method. This sample shows how to detect Code39 and Code128 barcodes. $reader = new BarCodeReader(); $reader->setBarCodeReadType(DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); $reader->setBarCodeImage("test.png"); foreach($reader->readBarCodes() as $result) { print("BarCode Type: ".$result->getCodeTypeName()); print("BarCode CodeText: ".$result->getCodeText()); }
barcodeTypes | The SingleDecodeType type array to read. |
setChecksumValidation | ( | $value | ) |
Enable checksum validation during recognition for 1D barcodes. Default is treated as Yes for symbologies which must contain checksum, as No where checksum only possible. Checksum never used: Codabar Checksum is possible: Code39 Standard/Extended, Standard2of5, Interleaved2of5, Matrix2of5, ItalianPost25, DeutschePostIdentcode, DeutschePostLeitcode, VIN Checksum always used: Rest symbologies
This sample shows influence of ChecksumValidation on recognition quality and results
$generator = new BarcodeGenerator(EncodeTypes::EAN_13, "1234567890128"); $generator->save("test.png"); $reader = new BarCodeReader("test.png", DecodeType::EAN_13); //checksum disabled $reader->setChecksumValidation(ChecksumValidation::OFF); foreach($reader->readBarCodes() as $result) { print("BarCode CodeText: ".$result->getCodeText()); print("BarCode Value: ".$result->getExtended()->getOneD()->getValue()); print("BarCode Checksum: ".$result->getExtended()->getOneD()->getCheckSum()); } $reader = new BarCodeReader("test.png", DecodeType::EAN_13); //checksum enabled $reader->setChecksumValidation(ChecksumValidation::ON); foreach($reader->readBarCodes() as $result) { print("BarCode CodeText: ".$result->getCodeText()); print("BarCode Value: ".$result->getExtended()->getOneD()->getValue()); print("BarCode Checksum: ".$result->getExtended()->getOneD()->getCheckSum()); } The checksum validation flag.
setCustomerInformationInterpretingType | ( | $value | ) |
Sets the Interpreting Type for the Customer Information of AustralianPost BarCode.Default is CustomerInformationInterpretingType::OTHER.
setDetectEncoding | ( | $value | ) |
A flag which force engine to detect codetext encoding for Unicode codesets. This sample shows how to detect text encoding on the fly if DetectEncoding is enabled $image = "image.png"; $generator = new BarcodeGenerator(EncodeTypes::QR, "пїЅпїЅпїЅпїЅпїЅ"); $generator->getParameters().getBarcode()->getQR()->setCodeTextEncoding("UTF-8"); $generator->save($image, BarCodeImageFormat.getPng()); //detects encoding for Unicode codesets is enabled $reader = new BarCodeReader($image, DecodeType::QR); $reader->setDetectEncoding(true); foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText()); //detect encoding is disabled $reader = new BarCodeReader($image, DecodeType::QR); $reader->setDetectEncoding(true); foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText());
setQualitySettings | ( | QualitySettings | $value | ) |
QualitySettings allows to configure recognition quality and speed manually. You can quickly set up QualitySettings by embedded presets: HighPerformance, NormalQuality, HighQuality, MaxBarCodes or you can manually configure separate options. Default value of QualitySettings is NormalQuality.
This sample shows how to use QualitySettings with BarCodeReader $reader = new BarCodeReader("test.png", DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); //set high performance mode $reader->setQualitySettings(QualitySettings::getHighPerformance()); foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText()); $reader = new BarCodeReader("test.png", DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); //normal quality mode is set by default foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText()); $reader = new BarCodeReader("test.png", DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); //set high performance mode $reader->setQualitySettings(QualitySettings::getHighPerformance()); //set separate options $reader->getQualitySettings()->setAllowMedianSmoothing(true); $reader->getQualitySettings()->setMedianSmoothingWindowSize(5); foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText()); QualitySettings to configure recognition quality and speed.
setStripFNC | ( | $value | ) |
Strip FNC1, FNC2, FNC3 characters from codetext. Default value is false.
This sample shows how to strip FNC characters
$generator = new BarcodeGenerator(EncodeTypes::GS1Code128, "(02)04006664241007(37)1(400)7019590754"); $generator->save("test.png"); $reader = new BarCodeReader("test.png", DecodeType::CODE_128); //StripFNC disabled $reader->setStripFNC(false); foreach($reader->readBarCodes() as $result) { print("BarCode CodeText: ".$result->getCodeText()); } $reader = new BarCodeReader("test.png", DecodeType::CODE_128); //StripFNC enabled $reader->setStripFNC(true); foreach($reader->readBarCodes() as $result) { print("BarCode CodeText: ".$result->getCodeText()); }
setTimeout | ( | $value | ) |
Sets the timeout of recognition process in milliseconds.
$reader = new BarCodeReader("test.png"); $reader->setTimeout(5000); foreach($reader->readBarCodes() as $result) print("BarCode CodeText: ".$result->getCodeText());
value | The timeout. |