Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 41 additions & 2 deletions lib/CXGN/Image.pm
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ use Image::ExifTool;
use JSON;
use Time::Piece;
use Time::Seconds;
use Imager;
use Barcode::ZBar;
use Image::Magick;

use base qw | CXGN::DB::ModifiableI |;

Expand Down Expand Up @@ -807,11 +810,11 @@ Extracts all the exif info from an image file
=cut

sub extract_exif_info {
my $self = shift;
my ($class, $filename) = @_;

my $et = Image::ExifTool->new();

my $info = $et->ImageInfo($self->get_filename("original"));
my $info = $et->ImageInfo($filename);

return $info;
}
Expand Down Expand Up @@ -865,6 +868,42 @@ sub extract_exif_info_class {
return $comment;
}

=head2 read_barcode

Function for reading and parsing info from barcodes using ZBar

=cut

sub read_barcode {
my ($class, $filename) = @_;

my $scanner = Barcode::ZBar::ImageScanner->new();
$scanner->parse_config("enable");

my $magick = Image::Magick->new();
$magick->Read($filename) && die;
my $raw = $magick->ImageToBlob(magick => 'GRAY', depth => 8);

my $image = Barcode::ZBar::Image->new();
$image->set_format('Y800');
$image->set_size($magick->Get(qw(columns rows)));
$image->set_data($raw);

my $n = $scanner->scan_image($image);

my $data;
my $type;
my @barcodes;

foreach my $symbol ($image->get_symbols()) {
$data = $symbol->get_data();
$type = $symbol->get_type();
push @barcodes, { type => $type, data => $data };
}
my $stock_id = $data;
return @barcodes;
}

=head2 make_dirs

Usage:
Expand Down