diff --git a/lib/CXGN/Image.pm b/lib/CXGN/Image.pm index 46b4016..9e46e76 100644 --- a/lib/CXGN/Image.pm +++ b/lib/CXGN/Image.pm @@ -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 |; @@ -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; } @@ -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: