Help language development. Donate to The Perl Foundation
Image::Libexif - An interface to libexif.
Operating System | Build Status | CI Provider |
---|---|---|
Linux | Travis CI |
High-level interface:
use v6; use Image::Libexif :tagnames; use Image::Libexif::Constants; #| Prints all the EXIF tags sub MAIN($file! where { .IO.f // die "file $file not found" }) { my Image::Libexif $e .= new: :$file; my @tags := $e.alltags: :tagdesc; say @tags».keys.flat.elems ~ ' tags found'; for ^EXIF_IFD_COUNT -> $group { say "Group $group: " ~ «'Image info' 'Camera info' 'Shoot info' 'GPS info' 'Interoperability info'»[$group]; for %(@tags[$group]).kv -> $k, @v { say "%tagnames{$k.Int}: @v[1] => @v[0]"; } } }
use v6; use Concurrent::File::Find; use Image::Libexif; use Image::Libexif::Constants; #| This program displays the EXIF date and time for every file in a directory tree sub MAIN($dir where {.IO.d // die "$dir not found"}) { my @files := find $dir, :extension('jpg'), :exclude-dir('thumbnails') :file, :!directory; @files.race.map: -> $file { my Image::Libexif $e .= new: :file($file); try say "$file " ~ $e.lookup(EXIF_TAG_DATE_TIME_ORIGINAL); # don't die if no EXIF is present $e.close; } }
Raw interface:
use v6; use Image::Libexif::Raw; use Image::Libexif::Constants; use NativeHelpers::Blob; #| This program extracts an EXIF thumbnail from an image and saves it into a new file (in the same directory as the original). sub MAIN($file! where { .IO.f // die "file '$file' not found" }) { my $l = exif_loader_new() // die ’Can't create an exif loader‘; # Load the EXIF data from the image file exif_loader_write_file($l, $file); # Get the EXIF data my $ed = exif_loader_get_data($l) // die ’Can't get the exif data‘; # The loader is no longer needed--free it exif_loader_unref($l); $l = Nil; if $ed.data && $ed.size { my $thumb-name = $file; $thumb-name ~~ s/\.jpg/_thumb.jpg/; my $data = blob-from-pointer($ed.data, :elems($ed.size), :type(Blob)); spurt $thumb-name, $data, :bin; } else { say "No EXIF thumbnail in file $file"; } # Free the EXIF data exif_data_unref($ed); }
For more examples see the example
directory.
Image::Libexif provides an interface to libexif and allows you to access the EXIF records of an image.
For more details on libexif see Lhttps://github.com/libexif and Lhttps://libexif.github.io/docs.html.
If asked to import the additional symbol tagnames
, Image::Libexif will make available the Hash %tagnames, which
has tag numbers as keys and a short description as values.
Creates an Image::Libexif object.
If the optional argument $file
is provided, then it will be opened and read; if not provided
during the initialization, the program may call the open
method later.
If the optional argument data
is provided, then the object will be initialized from the provided data; if not
provided during the initialization, the program may call the load
method later.
Opens a file and reads it into an initialiazed object (when no file or data has been provided during initialization).
Reads the data into an initialiazed object (when no file or data has been provided during initialization).
Closes the internal libexif object, frees the memory and cleans up.
Gathers some info:
ordercode
: the byte order as a codeorderstr
: the byte order as a stringdatatype
: the data typetagcount
: the number of tagsLooks up a tag in a specific group or in all groups. A tag may be present in more than one group. Group names are available as constants:
IMAGE_INFO
CAMERA_INFO
SHOOT_INFO
GPS_INFO
INTEROPERABILITY_INFO
Delivers all the tags in a specific group into a hash; the keys are the tag numbers. If the tag description is requested, the hash values are presented as an array [value, tag description].
Delivers an array of hashes, one for each group. If the tag description is requested, the hash values are presented as an array [value, tag description].
Reads the Maker Note data as an array of strings. Each string is a concatenation of the note description, name, title, and value.
Returns the thumbnail found in the original file, if any, as a Blob.
This functionality is available as a method and a sub, since the library doesn't really need a fully initialized
exif object.
To use the sub import it explicitly: use Image::Libexif :thumbnail;
.
There one case when an error may be returned: trying to open a non-existent file. This can happen while initializing an object with .new() and calling the .open() method. In both cases the method will return a Failure object, which can be trapped and the exception can be analyzed and acted upon.
This module requires the libexif library to be installed. Please follow the instructions below based on your platform:
sudo apt-get install libexif12
The module looks for a library called libexif.so.
To install it using zef (a module management tool):
$ zef update $ zef install Image::Libexif
To run the tests:
$ prove -e "perl6 -Ilib"
Image::Libexif relies on a C library which might not be present in one's installation, so it's not a substitute for a pure Perl6 module.
Fernando Santagata
The Artistic License 2.0