Ask Your Question
0

How do I access JPEG metadata from PERL

asked 2012-01-30 12:20:10 -0500

LarsPoulsen gravatar image

updated 2012-01-30 12:24:29 -0500

I have a large photo library hosted on my Linux server, and would like to be able to add titles, descriptions, comments and tags to them when they are displayed in my photo album browser (a PERL CGI program). Obviously, I would prefer for this descriptive matter to be embedded in the file itself, and I see that the JPEG file format has fields for this, which can in fact be very easily edited - even with the Windows file properties dialog.

How do I extract these fields using PERL on Linux?

I have tried using Image::MetaData::JPEG which would seem to be the right thing, but the only field I can see being displayed correctly is ImageDescription.

I do see an error message when I try to access the information:

Warning [segment type APP1] [obj Image::MetaData::JPEG::Segment=HASH(0x9864b78)]
0: --> "Using predictions" [at line 520 in /usr/local/share/perl5/Image/MetaData/JPEG/parsers/app1exif.pl]
1: Segment::parsemakernote(self, 'IFD0@SubIFD@MakerNoteData', 4938, 6, 3588) [at line 320 in /usr/local/share/perl5/Image/MetaData/JPEG/parsers/app1exif.pl]
2: Segment::parseifdchildren(self, 'IFD0@SubIFD', 6, 2762) [at line 268 in /usr/local/share/perl5/Image/MetaData/JPEG/parsers/app1exif.pl]
3: Segment::parseifd(self, 'IFD0@SubIFD', 2348, 6, 1) [at line 320 in /usr/local/share/perl5/Image/MetaData/JPEG/parsers/app1exif.pl]
4: Segment::parseifdchildren(self, 'IFD0', 6, 224) [at line 268 in /usr/local/share/perl5/Image/MetaData/JPEG/parsers/app1exif.pl]
5: Segment::parseifd(self, 'IFD0', 14, 6) [at line 85 in /usr/local/share/perl5/Image/MetaData/JPEG/parsers/app1exif.pl]
6: Segment::parseapp1exif(self) [at line 32 in /usr/local/share/perl5/Image/MetaData/JPEG/parsers/app1.pl]
7: Segment::parseapp1(self) [at line 134 in /usr/local/share/perl5/Image/MetaData/JPEG/Segment.pm]
8: (eval statement) [at line 118 in /usr/local/share/perl5/Image/MetaData/JPEG/Segment.pm]
9: Segment::parse(self, undef) [at line 87 in /usr/local/share/perl5/Image/MetaData/JPEG/Segment.pm]
10: Segment::new('Segment', 'APP1', 'SCALAR(0x9a79890)', undef) [at line 302 in /usr/local/share/perl5/Image/MetaData/JPEG.pm]
11: parse_segments('Image::MetaData::JPEG=HASH(0x984b238)', undef) [at line 82 in /usr/local/share/perl5/Image/MetaData/JPEG.pm]
12: (eval statement) [at line 81 in /usr/local/share/perl5/Image/MetaData/JPEG.pm]
13: new('Image::MetaData::JPEG', 'PattiBorgman-Downtown.jpg') [at line 6 in info.pl]

also:

 ** APP1 --> IFD1 ** ( 6 records)
                [              Compression]<0x0103> = [    SHORT]  6
                [              XResolution]<0x011a> = [ RATIONAL]  180/1
                [              YResolution]<0x011b> = [ RATIONAL]  180/1
                [           ResolutionUnit]<0x0128> = [    SHORT]  2
                [    JPEGInterchangeFormat]<0x0201> = [     LONG]  8966
                [ JPEGIntercha...matLength]<0x0202> = [     LONG]  4467
   2972B <0xe1  APP1> {Faulty segment:
 Can't modify non-lvalue subroutine call at /usr/local/share/perl5/Image/MetaData/JPEG/parsers/app1_xmp.pl line 163.}
        [                NAMESPACE]<......> = [    ASCII] "http://ns.adobe.com/xap/1.0/".
     65B <0xdb   DQT>
        [   PrecisionAndIdentifier]<......> = [  NIBBLES]  0 0
        [        QuantizationTable]<......> = [     BYTE]  1 1 1 ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2012-01-30 13:15:23 -0500

BRPocock gravatar image

The metadata in question is called EXIF. There are a few CPAN modules available, including Image::ExifTool, which is available on Fedora as the package perl-Image-ExifTool

After installing that package (e.g. pkcon install perl-Image-ExifTool) you can review the manual using man Image::ExifTool or perldoc Image::ExifTool.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2012-01-30 12:20:10 -0500

Seen: 908 times

Last updated: Jan 30 '12