Aspose.Barcode for PHP via Java  20.2
Aspose.Barcode for PHP via Java Generation and Recognition API docs
BarcodeReader Class Reference

Inherits BaseJavaClass.

Public Member Functions

 __construct ($image, $rectangles, $decodeTypes)
 
 containsAny (... $decodeTypes)
 
 getFileName ()
 
 getTimeout ()
 
 setTimeout ($value)
 
 getChecksumValidation ()
 
 setChecksumValidation ($value)
 
 getStripFNC ()
 
 setStripFNC ($value)
 
 getCustomerInformationInterpretingType ()
 
 setCustomerInformationInterpretingType ($value)
 
 close ()
 
 read ()
 
 getFoundBarCodes ()
 
 getFoundCount ()
 
 readBarCodes ()
 
 getQualitySettings ()
 
 setQualitySettings (QualitySettings $value)
 
 getCodeText ($includeCheckSum)
 
 getCheckSum ()
 
 getAngle ()
 
 getCodeBytes ()
 
 getMacroPdf417FileID ()
 
 getMacroPdf417SegmentID ()
 
 getMacroPdf417SegmentsCount ()
 
 getCode128DataPortions ()
 
 getQRStructuredAppendModeBarCodesQuantity ()
 
 getQRStructuredAppendModeBarCodeIndex ()
 
 getQRStructuredAppendModeParityData ()
 
 getIsDeniable ()
 
 getRegion ()
 
 getCodeType ()
 
 getCodeTypeName ()
 
 getRecognitionQuality ()
 
 getDetectEncoding ()
 
 setDetectEncoding ($value)
 
 setBarCodeImage ($image,... $areas)
 
 setBarCodeReadType (... $types)
 
 exportToXml ($xmlFile)
 

Detailed Description

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);
for($result : $reader->readBarCodes())
{
   print("BarCode Type: ".$result->getCodeTypeName());
   print("BarCode CodeText: ".$result->getCodeText());
}

Constructor & Destructor Documentation

◆ __construct()

__construct (   $image,
  $rectangles,
  $decodeTypes 
)

Initializes a new instance of the BarCodeReader

Parameters
argscan 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
Exceptions
PhpBarcodeException

Member Function Documentation

◆ close()

close ( )

Closes barcode reader.

◆ containsAny()

containsAny (   $decodeTypes)

Determines whether any of the given decode types is included into

Parameters
mixed...$decodeTypes Types to verify.
Returns
bool Value is a true if any types are included into.

◆ exportToXml()

exportToXml (   $xmlFile)

Exports BarCode properties to the xml-file specified

Parameters
xmlFileThe name for the file
Returns
Whether or not export completed successfully. Returns True in case of success; False Otherwise

◆ getAngle()

getAngle ( )

Gets the angle of the barcode (0-360).

Returns
The angle for barcode (0-360).
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getRegion()->getAngle() instead.

◆ getCheckSum()

getCheckSum ( )

Gets the checksum for 1D barcodes.

Returns
The checksum for 1D barcode.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getExtended()->getOneD()->getCheckSum() instead.

◆ getChecksumValidation()

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); for($result : $reader->readBarCodes()) { 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); for($result : $reader->readBarCodes()) { print("BarCode CodeText: ".$result->getCodeText()); print("BarCode Value: ".$result->getExtended()->getOneD()->getValue()); print("BarCode Checksum: ".$result->getExtended()->getOneD()->getCheckSum()); } The checksum validation flag.

◆ getCode128DataPortions()

getCode128DataPortions ( )

Gets Code128DataPortion instance for recognized Code128 barcode

Returns
The array of Code128DataPortion objects.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getExtended()->getCode128()->getCode128DataPortions() instead.

◆ getCodeBytes()

getCodeBytes ( )

Gets the encoded code bytes.

Returns
The code bytes of the barcode.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getCodeBytes() instead.

◆ getCodeText()

getCodeText (   $includeCheckSum)

Gets the code text. Text will not contain the checksum for 1D barcode types, which support the checksum. Please use GetCodeText(true) method to get result with checksum.

Returns
The code text of the barcode.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getCodeText() instead.

◆ getCodeType()

getCodeType ( )

Gets the barcode type.

Returns
The type information of the recognized barcode.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getCodeType() instead.

◆ getCodeTypeName()

getCodeTypeName ( )

Gets the name of the barcode type.

Returns
The type name of the recognized barcode.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getCodeTypeName() instead.

◆ getCustomerInformationInterpretingType()

getCustomerInformationInterpretingType ( )

Gets the Interpreting Type for the Customer Information of AustralianPost BarCode.Default is CustomerInformationInterpretingType::OTHER.

◆ getDetectEncoding()

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); for($result : $reader->readBarCodes()) print("BarCode CodeText: ".$result->getCodeText()); //detect encoding is disabled $reader = new BarCodeReader($image, DecodeType::QR); $reader->setDetectEncoding(false); for($result : $reader->readBarCodes()) print("BarCode CodeText: ".$result->getCodeText());

◆ getFileName()

getFileName ( )

Gets file name which was assigned by user

Returns
file name

◆ getFoundBarCodes()

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()

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

◆ getIsDeniable()

getIsDeniable ( )

Checks the deniable recognition. Such recognition might occur in QualitySettings::getMaxBarcodes() mode decoding or use QualitySettings::getAllowIncorrectBarcodes()

Returns
True if the deniable recognition was read.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getConfidence() instead.

◆ getMacroPdf417FileID()

getMacroPdf417FileID ( )

Gets the file ID of the barcode, only available with MacroPdf417.

Returns
The file ID for MacroPdf417
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getExtended()->getPdf417()->getMacroPdf417FileID() instead.

◆ getMacroPdf417SegmentID()

getMacroPdf417SegmentID ( )

Gets the segment ID of the barcode,only available with MacroPdf417.

Returns
The segment ID of the barcode.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getExtended()->getPdf417()->getMacroPdf417SegmentID() instead.

◆ getMacroPdf417SegmentsCount()

getMacroPdf417SegmentsCount ( )

Gets macro pdf417 barcode segments count. Default value is -1.

Returns
The segments count.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getExtended()->getPdf417()->getMacroPdf417SegmentsCount() instead.

◆ getQRStructuredAppendModeBarCodeIndex()

getQRStructuredAppendModeBarCodeIndex ( )

Gets the index of the QR structured append mode barcode. Index starts from 0. DEFAULT value is -1.

Returns
The index of the QR structured append mode barcode.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getExtended()->getQR()->getQRStructuredAppendModeBarCodeIndex() instead.

◆ getQRStructuredAppendModeBarCodesQuantity()

getQRStructuredAppendModeBarCodesQuantity ( )

Gets the QR structured append mode barcodes quantity. Default value is -1.

Returns
The quantity of the QR structured append mode barcode.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getExtended()->getQR()->getQRStructuredAppendModeBarCodesQuantity() instead.

◆ getQRStructuredAppendModeParityData()

getQRStructuredAppendModeParityData ( )

Gets the QR structured append mode parity data. Default value is -1.

Returns
The QR structured append mode parity data.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getExtended()->getQR()->getQRStructuredAppendModeParityData() instead.

◆ getQualitySettings()

getQualitySettings ( )
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()); for($result : $reader->readBarCodes()) print("BarCode CodeText: ".$result->getCodeText()); $reader = new BarCodeReader("test.png", DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); //normal quality mode is set by default for($result : $reader->readBarCodes()) 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); for($result : $reader->readBarCodes()) print("BarCode CodeText: ".$result->getCodeText()); QualitySettings to configure recognition quality and speed.

◆ getRecognitionQuality()

getRecognitionQuality ( )

Gets the recognition quality. Works for 1D and postal barcodes.

Returns
The recognition quality percent.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getReadingQuality() instead.

◆ getRegion()

getRegion ( )

Gets the barcode region.

Returns
The region of the recognized barcode.
Deprecated:
This method is obsolete. Use BarCodeReader->getFoundBarCodes()[]->getRegion() instead.

◆ getStripFNC()

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); for($result : $reader->readBarCodes()) { print("BarCode CodeText: ".$result->getCodeText()); } $reader = new BarCodeReader("test.png", DecodeType::CODE_128); //StripFNC enabled $reader->setStripFNC(true); for($result : $reader->readBarCodes()) { print("BarCode CodeText: ".$result->getCodeText()); }

◆ getTimeout()

getTimeout ( )

Gets the timeout of recognition process in milliseconds.

$reader = new BarCodeReader("test.png"); $reader->setTimeout(5000); for($result : $reader->readBarCodes()) print("BarCode CodeText: ".$result->getCodeText());

Returns
The timeout.

◆ read()

read ( )

Reads barcode from the image.

Detect AllSupportedTypes

$full_path = "test.png"; $reader = new BarcodeReader($full_path); while($reader->read()) { print($reader->getCodeText(false)); print($reader->getCodeTypeName()); } reader->close();

Returns
True if the next barcode was read successfully; false if there are no more nodes to read.

◆ readBarCodes()

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); for($result : $reader->readBarCodes()) 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());

Returns
Returns array of recognized s on the image. If nothing is recognized, zero array is returned.

◆ setBarCodeImage()

setBarCodeImage (   $image,
  $areas 
)
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) }); for($result : $reader->readBarCodes()) { print("BarCode Type: ".$result->getCodeTypeName()); print("BarCode CodeText: ".$result->getCodeText()); }

Parameters
valueThe bitmap image for recognition.
areasareas list for recognition
Exceptions
BarcodeException

◆ setBarCodeReadType()

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"); for($result : $reader->readBarCodes()) { print("BarCode Type: ".$result->getCodeTypeName()); print("BarCode CodeText: ".$result->getCodeText()); }

Parameters
barcodeTypesThe SingleDecodeType type array to read.

◆ setChecksumValidation()

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); for($result : $reader->readBarCodes()) { 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); for($result : $reader->readBarCodes()) { print("BarCode CodeText: ".$result->getCodeText()); print("BarCode Value: ".$result->getExtended()->getOneD()->getValue()); print("BarCode Checksum: ".$result->getExtended()->getOneD()->getCheckSum()); } The checksum validation flag.

◆ setCustomerInformationInterpretingType()

setCustomerInformationInterpretingType (   $value)

Sets the Interpreting Type for the Customer Information of AustralianPost BarCode.Default is CustomerInformationInterpretingType::OTHER.

◆ setDetectEncoding()

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); for($result : $reader->readBarCodes()) print("BarCode CodeText: ".$result->getCodeText()); //detect encoding is disabled $reader = new BarCodeReader($image, DecodeType::QR); $reader->setDetectEncoding(true); for($result : $reader->readBarCodes()) print("BarCode CodeText: ".$result->getCodeText());

◆ setQualitySettings()

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()); for($result : $reader->readBarCodes()) print("BarCode CodeText: ".$result->getCodeText()); $reader = new BarCodeReader("test.png", DecodeType::CODE_39_STANDARD, DecodeType::CODE_128); //normal quality mode is set by default for($result : $reader->readBarCodes()) 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); for($result : $reader->readBarCodes()) print("BarCode CodeText: ".$result->getCodeText()); QualitySettings to configure recognition quality and speed.

◆ setStripFNC()

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); for($result : $reader->readBarCodes()) { print("BarCode CodeText: ".$result->getCodeText()); } $reader = new BarCodeReader("test.png", DecodeType::CODE_128); //StripFNC enabled $reader->setStripFNC(true); for($result : $reader->readBarCodes()) { print("BarCode CodeText: ".$result->getCodeText()); }

◆ setTimeout()

setTimeout (   $value)

Sets the timeout of recognition process in milliseconds.

$reader = new BarCodeReader("test.png"); $reader->setTimeout(5000); for($result : $reader->readBarCodes()) print("BarCode CodeText: ".$result->getCodeText());

Parameters
valueThe timeout.