public static function run($dataDir = null) { # initialize barcode reader $img = $dataDir . "barcode.jpg"; $barcode_reader_type = new BarCodeReadType(); $reader = new BarCodeReader($img, $barcode_reader_type->Code39Standard); # Try to recognize all possible barcodes in the image while (java_values($reader->read())) { # Display the symbology type print "BarCode Type: " . (string) $reader->getReadType() . PHP_EOL; # Display the codetext print "BarCode CodeText: " . (string) $reader->getCodeText() . PHP_EOL; # Get the barcode region $region = $reader->getRegion(); if ($region != null) { # Initialize an object of type BufferedImage to get the Graphics object $imageIO = new ImageIO(); // $file=new File(); $bufferedImage = $imageIO->read(new File($img)); # Initialize graphics object from the image $g = $bufferedImage->getGraphics(); $color = new Color(); # Initialize paint object $p = new GradientPaint(0, 0, $color->red, 100, 100, $color->pink, true); $region->drawBarCodeEdges($g, $color->RED); # Save the image $imageIO->write($bufferedImage, "png", new File($dataDir . "Code39StdOut.png")); } } # Close reader $reader->close(); }
public static function run($dataDir = null) { $img = $dataDir . "barcode.jpg"; # initialize barcode reader $barcode_reader_type = new BarCodeReadType(); $reader = new BarCodeReader($img, $barcode_reader_type->Code39Standard); # Call read method $reader->read(); # Now get all possible barcodes $barcodes = $reader->getAllPossibleBarCodes(); $i = 0; while (java_values($i < strlen($barcodes))) { # Display code text, symbology, detected angle, recognition percentage of the barcode print "Code Text: " . (string) $barcodes[$i]->getCodetext() . " Symbology: " . (string) $barcodes[$i]->getBarCodeReadType() . " Recognition percentage: " . (string) $barcodes[$i]->getAngle() . PHP_EOL; # Display x and y coordinates of barcode detected $point = $barcodes[$i]->getRegion()->getPoints(); print "Top left coordinates: X = " . (string) $point[0]->getX() . ", Y = " . (string) $point[0]->getY() . PHP_EOL; print "Bottom left coordinates: X = " . (string) $point[1]->getX() . ", Y = " . (string) $point[1]->getY() . PHP_EOL; print "Bottom right coordinates: X = " . (string) $point[2]->getX() . ", Y = " . (string) $point[2]->getY() . PHP_EOL; print "Top right coordinates: X = " . (string) $point[3]->getX() . ", Y = " . (string) $point[3]->getY() . PHP_EOL; break; } # Close reader $reader->close(); }
public static function run($dataDir = null) { $img = $dataDir . "barcode.jpg"; # initialize barcode reader $barcode_reader_type = new BarCodeReadType(); $reader = new BarCodeReader($img, $barcode_reader_type->Code39Standard); # Call read method while (java_values($reader->read())) { print "Barcode CodeText: " . (string) $reader->getCodeText() . " Barcode Type: " . (string) $reader->getReadType() . PHP_EOL; $percent = $reader->getRecognitionQuality(); print "Barcode Quality Percentage: " . (string) $percent . PHP_EOL; } # Close reader $reader->close(); }
public static function run($dataDir = null) { # Open the stream. Read only access is enough for Aspose.BarCode to load an image. $stream = new FileInputStream($dataDir . "test.png"); # Create an instance of BarCodeReader class # and specify an area to look for the barcode $barcode_reader_type = new BarCodeReadType(); $reader = new BarCodeReader($stream, new Rectangle(0, 0, 10, 50), $barcode_reader_type->Code39Standard); # TRead all barcodes in the provided area while (java_values($reader->read())) { # Display the codetext and symbology type of the barcode found print "Codetext: " . (string) $reader->getCodeText() + " Symbology: " . (string) $reader->getReadType() . PHP_EOL; } # Close reader $reader->close(); }
public static function run($dataDir = null) { $img = $dataDir . "barcode.jpg"; # initialize barcode reader $barcode_reader_type = new BarCodeReadType(); $reader = new BarCodeReader($img, $barcode_reader_type->Code39Standard); # Set recognition mode $recognitionMode = new RecognitionMode(); $reader->setRecognitionMode($recognitionMode->ManualHints); # Set manual hints $manualHint = new ManualHint(); $reader->setManualHints($manualHint->InvertImage); $reader->setManualHints($manualHint->IncorrectBarcodes); # Call read method while (java_values($reader->read())) { print "Barcode CodeText: " . (string) $reader->getCodeText() . PHP_EOL; } # Close reader $reader->close(); }
public static function run($dataDir = null) { # initialize barcode reader $img = $dataDir . "barcode.jpg"; $barcode_reader_type = new BarCodeReadType(); $reader = new BarCodeReader($img, $barcode_reader_type->Code39Standard); # Try to recognize all possible barcodes in the image while (java_values($reader->read())) { # Get the region information $region = $reader->getRegion(); if ($region != null) { # Display x and y coordinates of barcode detected $point = $region->getPoints(); print "Top left coordinates: X = " . (string) $point[0]->x . ", Y = " . (string) $point[0]->y . PHP_EOL; print "Bottom left coordinates: X = " . (string) $point[1]->x . ", Y = " . (string) $point[1]->y . PHP_EOL; print "Bottom right coordinates: X = " . (string) $point[2]->x . ", Y = " . (string) $point[2]->y . PHP_EOL; print "Top right coordinates: X = " . (string) $point[3]->x . ", Y = " . (string) $point[3]->y . PHP_EOL; } print "Codetext: " . (string) $reader->getCodeText() . PHP_EOL; } # Close reader $reader->close(); }