Aspose.Barcode for PHP via Java Generation and Recognition API docs

Inherits BaseJavaClass.

Public Member Functions

 __construct ($imageResource, $areas, $decodeTypes)
 
 containsAny (... $decodeTypes)
 
 getTimeout ()
 
 setTimeout (int $value)
 
 abort ()
 
 getFoundBarCodes ()
 
 getFoundCount ()
 
 setBarCodeImage ($imageResource, ?Rectangle ... $areas)
 
 setBarCodeReadType (int ... $types)
 
 getBarCodeDecodeType ()
 
 exportToXml (string $xmlFile)
 
- Public Member Functions inherited from BaseJavaClass
 __construct ($javaClass)
 
 getJavaClass ()
 
 getJavaClassName ()
 
 isNull ()
 
 printJavaClassName ()
 

Static Public Member Functions

static importFromXml ($resource)
 

Protected Member Functions

 init ()
 
- Protected Member Functions inherited from BaseJavaClass
 setJavaClass ($javaClass)
 

Static Private Member Functions

static construct ($javaClass)
 

Private Attributes

 $qualitySettings
 
 $recognizedResults
 
 $barcodeSettings
 
const JAVA_CLASS_NAME = "com.aspose.mw.barcode.recognition.MwBarCodeReader"
 

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.

foreach($reader->readBarCodes() as $result)
{
print("BarCode Type: ".$result->getCodeTypeName());
print("BarCode CodeText: ".$result->getCodeText());
}

Constructor & Destructor Documentation

◆ __construct()

BarCodeReader::__construct (   $imageResource,
  $areas,
  $decodeTypes 
)

BarCodeReader constructor. Initializes a new instance of the BarCodeReader

Parameters
string | GdImage$imageResourceimage encoded as GDImage, file resource, base64 string or path to image resource (located in the file system or via http)
Rectangle | array | null$areasarray of object by type Rectangle
int | array | null$decodeTypesarray of decode types
Exceptions
BarcodeException

Member Function Documentation

◆ abort()

BarCodeReader::abort ( )

◆ construct()

static BarCodeReader::construct (   $javaClass)
staticprivate

◆ containsAny()

BarCodeReader::containsAny (   $decodeTypes)

Determines whether any of the given decode types is included into

Parameters
array$decodeTypesTypes to verify.
Returns
bool Value is a true if any types are included into.

◆ exportToXml()

BarCodeReader::exportToXml ( string  $xmlFile)

Exports BarCode properties to the xml-file specified

Parameters
string$xmlFileThe path to xml file
Returns
bool Whether or not export completed successfully. Returns True in case of success; False Otherwise

◆ getBarCodeDecodeType()

BarCodeReader::getBarCodeDecodeType ( )

◆ getFoundBarCodes()

BarCodeReader::getFoundBarCodes ( )

Gets recognized BarCodeResult array

This sample shows how to read barcodes with BarCodeReader

$reader->readBarCodes();
for($i = 0; $reader->getFoundCount() > $i; ++$i)
{
print("BarCode CodeText: ". $reader->getFoundBarCodes()[$i]->getCodeText());
}

Value: The recognized BarCodeResult array

◆ getFoundCount()

BarCodeReader::getFoundCount ( )

Gets recognized barcodes count

This sample shows how to read barcodes with BarCodeReader

$reader->readBarCodes();
for($i = 0; $reader->getFoundCount() > $i; ++$i)
print("BarCode CodeText: ".$reader->getFoundBarCodes()[i]->getCodeText());

Value: The recognized barcodes count

◆ getTimeout()

BarCodeReader::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());
Returns
timeout.

◆ importFromXml()

static BarCodeReader::importFromXml (   $resource)
static

Import BarCode properties from xml file

Parameters
string$resourceThe name of the xml file or path to http resource
Returns
BarCodeReader
Exceptions
BarcodeException

◆ init()

BarCodeReader::init ( )
protected

Reimplemented from BaseJavaClass.

◆ setBarCodeImage()

BarCodeReader::setBarCodeImage (   $imageResource,
?Rectangle ...  $areas 
)
final

Reads BarCodeResult from the image.

This sample shows how to read barcodes with BarCodeReader
foreach($reader->readBarCodes() as $result)
print("BarCode CodeText: ".$result->getCodeText());
$reader->readBarCodes();
for($i = 0; $reader->getFoundCount() > $i; ++$i)
print("BarCode CodeText: ".$reader->getFoundBarCodes()[i]->getCodeText());
@return array of recognized {@code BarCodeResult}s on the image. If nothing is recognized, zero array is returned.
/
public function readBarCodes(): array
{
try
{
$this->recognizedResults = array();
$javaReadBarcodes = java_values($this->getJavaClass()->readBarCodes());
for ($i = 0; $i < sizeof($javaReadBarcodes); $i++)
{
$this->recognizedResults[$i] = new BarCodeResult($javaReadBarcodes[$i]);
}
}
catch (Exception $e)
{
if (strpos($e->getMessage(), "RecognitionAbortedException"))
{
throw new RecognitionAbortedException($e->getMessage(), null);
}
throw $e;
}
}
/**
* 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.
* @code
* 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, 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, 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());
*
* @return QualitySettings to configure recognition quality and speed.
* @throws BarcodeException
*/
public final function getQualitySettings(): QualitySettings
{
try
{
}
catch (Exception $ex)
{
throw new BarcodeException($ex->getMessage(), __FILE__, __LINE__);
}
}
/**
* 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.
* @code
* 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, 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, 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());
*
* @param QualitySettings $value QualitySettings to configure recognition quality and speed.
* @throws BarcodeException
*/
public function setQualitySettings(QualitySettings $value): void
{
try
{
$this->getJavaClass()->setQualitySettings($value->getJavaClass());
//$this->qualitySettings = new QualitySettings($this->getJavaClass()->getQualitySettings());
}
catch (Exception $ex)
{
throw new BarcodeException($ex->getMessage(), __FILE__, __LINE__);
}
}
/**
* The main BarCode decoding parameters. Contains parameters which make influence on recognized data.
* @return BarcodeSettings BarCode decoding parameters
*/
public function getBarcodeSettings(): BarcodeSettings
{
}
/**
* Sets bitmap image and areas for recognition.
* Must be called before ReadBarCodes() method.
*
* This sample shows how to detect Code39 and Code128 barcodes.
* @code
* $bmp = "test.png";
* $reader = new BarCodeReader();
* $reader->setBarCodeReadType(DecodeType::CODE_39, 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());
* }
*
Parameters
string$resourceimage encoded as base64 string or path to image resource located in the file system or via http
Rectangle | null$areasareas list for recognition
Exceptions
BarcodeException

◆ setBarCodeReadType()

BarCodeReader::setBarCodeReadType ( int ...  $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, DecodeType::CODE_128);
$reader->setBarCodeImage("test.png");
foreach($reader->readBarCodes() as $result)
{
print("BarCode Type: ".$result->getCodeTypeName());
print("BarCode CodeText: ".$result->getCodeText());
}
Parameters
array$typesThe SingleDecodeType type array to read.

◆ setTimeout()

BarCodeReader::setTimeout ( int  $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());
Parameters
valueThe timeout.

Member Data Documentation

◆ $barcodeSettings

BarCodeReader::$barcodeSettings
private

◆ $qualitySettings

BarCodeReader::$qualitySettings
private

◆ $recognizedResults

BarCodeReader::$recognizedResults
private

◆ JAVA_CLASS_NAME

const BarCodeReader::JAVA_CLASS_NAME = "com.aspose.mw.barcode.recognition.MwBarCodeReader"
private