The Image::ExifTool Perl Library Module
Description
The Image::ExifTool library provides an extensible set of Perl modules to read and
write meta information in a wide variety of image, audio and video files.
Index
The following sections of this document give examples of how to use Image::ExifTool,
and explain the following individual functions in more detail:
The ExifTool module may be used by simply calling the
ImageInfo function:
use Image::ExifTool qw(:Public);
my $info = ImageInfo('image.jpg');
|
or in a more object-oriented fashion, by creating an ExifTool object:
use Image::ExifTool qw;
my $exifTool = new Image::ExifTool;
my $info = $exifTool->ImageInfo('image.jpg');
|
The object-oriented method allows more flexibility, but is slightly more
complicated. You choose the method that you prefer.
The $info value returned by ImageInfo in the above
examples is a reference to a hash containing the tag/value pairs. Here is a
simplified example which prints out this information:
foreach (keys %$info) {
print "$_ => $$info{$_}\n";
}
|
See ImageInfo for a more detailed description of the
info hash entries.
And the technique for writing meta information is equally simple:
use Image::ExifTool;
my $exifTool = new Image::ExifTool;
$exifTool->SetNewValue(Author => 'Phil Harvey');
$exifTool->WriteInfo('image.jpg','modified_image.jpg');
|
User-defined tags can be added via the ExifTool configuration file or by defining
the %Image::ExifTool::UserDefined hash before calling any ExifTool functions. See
"ExifTool_config" in the ExifTool distribution for
more details. If necessary, the configuration feature can be disabled by setting
the ExifTool "noConfig" flag before loading Image::ExifTool. ie)
BEGIN { $Image::ExifTool::noConfig = 1 }
use Image::ExifTool;
|
Obtain meta information from image. This is the one-step function for obtaining
meta information from an image. Internally, ImageInfo
calls ExtractInfo to extract data from the image, and
GetInfo and GetTagList to
generate the returned information hash and tag list.
Prototype | ImageInfo($;@) |
Inputs | 0) [optional] ExifTool object reference
1) File name, file reference or scalar reference
2-N) [optional] list of tag names to find (or tag list reference or
options reference, see below)
|
Returns | Reference to hash of tag key/value pairs |
Examples:
Non object-oriented example showing use of options and returning tag list:
use Image::ExifTool qw(ImageInfo);
my @ioTagList;
my $info;
$info = ImageInfo('image.jpg', \@ioTagList, {Sort => 'Group0'});
|
Object-oriented example to read from a file that is already open:
my $exifTool = new Image::ExifTool;
$info = $exifTool->ImageInfo(\*FILE_PT, 'Aperture', 'ShutterSpeed', 'ISO');
|
Extract information from an image in memory:
$info = $exifTool->ImageInfo(\$imageData);
|
Extract information from an embedded thumbnail image:
$info = ImageInfo('image.jpg', 'thumbnailimage');
my $thumbInfo = ImageInfo($$info{ThumbnailImage});
|
Using an ExifTool object to set the options before calling
ImageInfo:
my $filename = shift || die "Please specify filename\n";
my @ioTagList = qw(filename imagesize xmp:creator exif:* -ifd1:*);
$exifTool->Options(Unknown => 1, DateFormat => '%H:%M:%S %a. %b. %e, %Y');
$info = $exifTool->ImageInfo($filename, \@ioTagList);
|
Function Arguments:
ImageInfo is very flexible about the arguments
passed to it, and interprets them based on their type. It may be called with
one or more arguments. The one required argument is either a SCALAR (the image
file name), a file reference (a reference to the image file) or a SCALAR
reference (a reference to the image in memory). Other arguments are optional.
The order of the arguments is not significant, except that the first SCALAR is
taken to be the file name unless a file reference or scalar reference comes
earlier in the argument list.
Below is a more detailed explanation of how the ImageInfo
function arguments are interpreted.
ExifTool ref |
ImageInfo may be called with an ExifTool object if
desired. The advantage of using the object-oriented form of this function is
that after ImageInfo returns, you may use the
object-oriented functions below to obtain additional information if required.
Must be the first argument if used.
|
SCALAR |
The first scalar argument is taken to be the file name unless an earlier
argument specified the image data via a file reference (file ref) or data
reference (SCALAR ref). The remaining scalar arguments are names of tags
for requested information. If no tags are specified, all possible information
is extracted. Tag names are case-insensitive and may be prefixed
by a optional group names separated by colons. A group name may begin with a
family number (ie. '1IPTC:Keywords '), to restrict matches to a
specific family. A tag name of '* ' may be used, thus allowing
'GROUP:* ' to represent all tags in a specific group, or a group
name of '* ' may be used, in which case all available instances of
the specified tag are returned regardless of the
Duplicates setting (ie. '*:WhiteBalance ').
And finally, a leading '- ' indicates tags to be excluded (ie.
'-IFD1:* ').
Note that keys in the returned information hash and elements of the
returned tag list are not necessarily the same as these tag names -- group
names are removed, the case may be changed, and an instance number may be
added. For this reason it is best to use either the keys of the returned
hash or the elements of the tag array when accessing the tag values.
See the TagNames documentation for a
complete list of ExifTool tag names.
|
File ref |
A reference to an open image file. If you use this method (or a SCALAR
reference) to access information in an image, the FileName and Directory tags
will not be returned. (Also, the FileSize and FileModifyDate tags will not be
returned unless it is a plain file.) Image processing begins at the current
file position, and on return the file position is unspecified. May be either a
standard GLOB reference or a reference to a File::RandomAccess object.
[Advanced: To allow a non-rewindable stream (ie. a network socket) to be
re-read after processing with ExifTool, first wrap the file reference in a
File::RandomAccess object, then pass this object to
ImageInfo. The File::RandomAccess object will buffer
the file if necessary, and may be used to re-read the file after
ImageInfo returns.]
|
SCALAR ref |
A reference to image data in memory.
|
ARRAY ref |
Reference to a list of tag names. On entry, any elements in the list are
added to the list of requested tags. On return, this list is updated to
contain an ordered list of tag keys for all extracted tags.
|
HASH ref |
Reference to a hash containing the options settings. See
Options documentation below for a list of available
options. Options specified as arguments to ImageInfo
take precedence over Options settings.
|
Return Value:
ImageInfo returns a reference to a hash of tag
key/value pairs. The tag keys are identifiers, which are similar to the tag
names but may have an embedded instance number if multiple tags with the
same name were extracted from the image. Many of the ExifTool functions
require a tag key as an argument. Use GetTagName
to get the tag name for a given tag key. Note that the case of the tag
names may not be the same as requested.
Values of the returned hash are usually simple scalars, but a scalar
reference is used to indicate binary data and an array reference may be used
to indicate a list. Lists of values are joined by commas into a single
string only if the PrintConv option is enabled and the List option is
disabled (which are the defaults). Note that binary values are not
necessarily extracted unless specifically requested or the Binary option is
set. If not extracted the value is a reference to a string of the form
"Binary data ##### bytes
".
Here is a simple example to print out the information returned by
ImageInfo. It shows how to print out a human-friendly
output for all returned tag values, and works for either setting of the
PrintConv option (although binary data will be printed to the console if
PrintConv is disabled):
foreach (keys %$info) {
my $val = $$info{$_};
if (ref $val eq 'ARRAY') {
$val = join(', ', @$val);
} elsif (ref $val eq 'SCALAR') {
$val = '(Binary data)';
}
printf("%-24s : %s\n", $_, $val);
}
|
and gives output like this (PrintConv enabled):
WhiteBalance : Auto
FNumber : 3.5
InteroperabilityOffset : 936
XResolution : 72
ISO : 100
ThumbnailImage : (Binary data)
FlashOn : On
Make : FUJIFILM
ShutterSpeedValue : 1/64
ExposureCompensation : 0
Sharpness : Soft
ResolutionUnit : inches
|
Notes:
As well as tags representing information extracted from the image,
the following tags generated by ExifTool may be returned:
ExifToolVersion | The ExifTool version number |
Error | An error message if the image could not be processed |
Warning | A warning message if problems were encountered
while processing the image |
Create a new ExifTool object.
Example:
my $exifTool = new Image::ExifTool;
|
Note that ExifTool uses AUTOLOAD to load non-member methods, so any class
using Image::ExifTool as a base class must define an AUTOLOAD which calls
Image::ExifTool::DoAutoLoad(). ie)
sub AUTOLOAD
{
Image::ExifTool::DoAutoLoad($AUTOLOAD, @_);
}
|
The following functions require an ExifTool object as the first argument
|
Get/set ExifTool options. This function can be called to set the default
options for an ExifTool object. Options set this way are in effect for
all function calls but may be overridden by options passed as arguments
to a specific function.
Prototype | Options($$;@) |
Inputs | 0) ExifTool object reference
1) Parameter name (see table below)
2) [optional] Option value if specified (may be undef to clear option)
3-N) [optional] Additional parameter/value pairs
|
Returns | Previous value of last specified parameter |
Available options:
ExifTool Options |
Option | Description | Values | Default |
Binary | Flag to extract the value data for all binary tags.
Tag values representing large binary data blocks (ie. ThumbnailImage)
are not necessarily extracted unless this option is set or the tag is
specifically requested by name. |
0 or 1 | 0 |
ByteOrder | The byte order for newly created EXIF segments when
writing. Note that if EXIF information already exists, the existing order is
maintained. If ByteOrder is not defined, then the order of the maker notes is
used (if they are being copied), otherwise big-endian ('MM') order is assumed.
This can also be set via the ExifByteOrder tag, but the ByteOrder option takes
precedence if both are set. |
'MM','II' or undef | undef |
Charset | Character set for encoding character strings containing code
points above U+007F. Note that this option affects some types of information when
reading/writing the file and other types when getting/setting tag values, so it must
be defined for both types of access. |
UTF8 - | UTF-8 characters |
Latin - | Windows Latin1 (cp1252) |
| 'UTF8' |
Compact | Flag to write compact output. The XMP specification suggests
that the data be padded with blanks to allow in-place editing. By setting this
flag, 2kB is saved for files with XMP data. |
0 or 1 | 0 |
Composite | Flag to calculate Composite tags | 0 or 1 | 1 |
Compress | Flag to write new values in compressed format if possible.
Has no effect unless Compress::Zlib is installed. |
0 or 1 | 0 |
CoordFormat | Output format for GPS coordinates |
A printf-style format string with specifiers for degrees, minutes and
seconds in that order, however minutes and seconds may be omitted. The
default is equivalent to a format string of
q{%d deg %d' %.2f"} .
| undef |
DateFormat | Output format for date/time values. If date can not
be converted, value is left unchanged unless the StrictDate option is set.
Timezones are ignored. | See strftime manpage for details. The default
is similar to a format string of "%Y:%m:%d %H:%M:%S" . |
undef |
Duplicates | Flag to return values from
tags with duplicate names when extracting information |
0 or 1 | 1 |
Exclude |
Exclude specified tags |
Tag name or reference to a list of tag names to exclude. Case is not significant.
Tags may also be excluded by preceding their name with a '-' in the arguments to ImageInfo. |
undef |
ExtractEmbedded |
Flag to extract information from embedded documents in PostScript files and
the AIPrivateData stream in PDF files |
0 or 1 | 0 |
FastScan |
Flag to increase speed of extracting information from JPEG images. With this
option set, ExifTool will not scan to the end of a JPEG image to check for an AFCP,
CanonVRD, FotoStation, PhotoMechanic, MIE or PreviewImage trailer. Also, when
combined with the ScanForXMP option, prevents scanning for XMP in recognized file
types. |
0 or 1 | 0 |
FixBase |
Fix maker notes base offset. Allows values to be extracted from maker notes
which have been corrupted by editing with 3rd party software. |
An integer specifying a value to be added to the maker notes base offset, or the
empty string ('') for ExifTool to take its best guess at the correct base. |
undef |
Group# | Extract tags for specified groups |
Group name or reference to list of group names.
Group name may begin with '-' to exclude a group. Case IS significant.
See GetGroup for a description of group families,
and GetAllGroups for a list of available groups. |
undef |
HtmlDump | Dump information in hex to a dynamic HTML web page.
Option value sets a limit on the maximum block size. Output file is
specified by the TextOut option. |
0 = | No HTML dump |
1 = | 1 KB size limit |
2 = | 16 KB size limit |
3 = | Full dump |
| 0 |
HtmlDumpBase | Specifies the base for HTML dump offsets. If not
defined, the EXIF/TIFF base offset is used. |
0 = | Absolute offsets |
non-zero = | Relative offsets |
undef = | EXIF/TIFF offsets |
| undef |
IgnoreMinorErrors | Flag to ignore minor errors. Causes minor errors
to be downgraded to warnings, and minor warnings to be ignored.
This option is provided mainly to allow writing of files when minor errors
occur, but also allows thumbnail and preview images to be extracted even if
they don't have a recognizable header. |
0 or 1 | 0 |
Lang | Localized language for exiftool tag descriptions, etc. If the
specified language isn't available, the option is not changed. May be set to
undef to select the built-in default language. |
String corresponding to the name of a module in Image/ExifTool/Lang. |
'en' |
List | Flag to extract lists of PrintConv values into arrays instead of combining
them into a string of values. | 0 or 1 | 0 |
ListSep | Separator string used to join lists of PrintConv values when
List option is not set. | any string | ', ' |
ListSplit | Regular expression used to split values of list-type tags
into individual items when writing. (ie. use ',\\s*' to split a comma-separated list) |
A regular expression pattern | undef |
MakerNotes | Option to extract MakerNotes and other writable
subdirectories (such as PrintIM) as a data block. Normally when the MakerNotes
are extracted they are rebuilt to include data outside the boundaries of the
original maker note data block, but a value of 2 disables this feature. |
0 = | Don't extract writable subdirectories |
1 = | Extract and rebuild makernotes into self-contained block |
2 = | Extract without rebuilding makernotes |
| 0 |
MissingTagValue | Value for missing tags in
expressions evaluated by SetNewValuesFromFile.
If not set, a minor error is issued for missing values, or the value
is set to '' if IgnoreMinorErrors is set. |
Any string, or undef | undef |
PrintConv | Flag to enable print conversion. Also enables inverse print
conversion for writing. | 0 or 1 | 1 |
ScanForXMP | Flag for scan all files (even unrecognized
formats) for XMP information unless XMP was already found in the file. When combined with
the FastScan option, only unrecognized file types are scanned for XMP.
| 0 or 1 | 0 |
Sort | Specifies order to sort tags in the returned tag list |
Input | Sort in same order as input tag arguments |
Alpha | Sort alphabetically |
File | Sort in order that tags were found in the file |
Group# | Sort by tag group,
where # is zero or more family numbers separated by colons. If # is not specified,
Group0 is assumed. See GetGroup for a description of group
families. |
| 'Input' |
StrictDate | Flag to return undefined value for any date which can't be
converted when the DateFormat option is used. |
0 or 1 | 0 |
TextOut | Output file for Verbose and HtmlDump options. |
File reference | \*STDOUT |
Unknown | Control extraction of unknown tags |
0 = | Unknown tags not extracted |
1 = | Unknown tags are extracted from EXIF
(and other tagged-format) directories |
2 = | Unknown tags also extracted from binary data blocks |
| 0 |
Verbose | Print verbose messages to file specified by TextOut option.
Click here for example outputs. |
0 = | No verbose messages |
1 = | Print tag names and raw values |
2 = | Add additional tag details |
3 = | Add hex dump of tag data (with length limits) |
4 = | Remove length limit on dump of tag values |
5 = | Remove length limit on dump of JPEG segments |
| 0 |
Examples:
# exclude the 'OwnerName' tag from returned information
$exifTool->Options(Exclude => 'OwnerName');
|
# only get information in EXIF or MakerNotes groups
$exifTool->Options(Group0 => ['EXIF', 'MakerNotes']);
|
# ignore information from IFD1
$exifTool->Options(Group1 => '-IFD1');
|
# sort by groups in family 2, and extract unknown tags
$exifTool->Options(Sort => 'Group2', Unknown => 1);
|
# reset DateFormat option
$exifTool->Options(DateFormat => undef);
|
# do not extract duplicate tag names
$oldSetting = $exifTool->Options(Duplicates => 0);
|
# get current Verbose setting
$isVerbose = $exifTool->Options('Verbose');
|
Reset all options to their default values.
Prototype | ClearOptions() |
Inputs | 0) ExifTool object reference
|
Extract all meta information from an image.
Prototype | ExtractInfo($;@) |
Inputs | 0) ExifTool object reference
1-N) Same as ImageInfo except that a list of tag
keys is not returned if an ARRAY reference is given.
|
Returns | 1 if this was a valid image, 0 otherwise |
Example:
$success = $exifTool->ExtractInfo('image.jpg', \%options);
|
The following options are effective in the call to ExtractInfo:
Binary, Charset, Composite, ExtractEmbedded, FastScan, FixBase, HtmlDump, HtmlDumpBase,
IgnoreMinorErrors, Lang, MakerNotes, ScanForXMP, TextOut, Unknown and Verbose.
GetInfo is called to return meta information
after it has been extracted from the image by a previous call to
ExtractInfo or ImageInfo.
This function may be called repeatedly after a single call to
ExtractInfo or ImageInfo.
Prototype | GetInfo($;@) |
Inputs | 0) ExifTool object reference
1-N) Same as ImageInfo except that an image
can not be specified
|
Returns | Reference to information hash, the same as with
ImageInfo |
Examples:
$info = $exifTool->GetInfo('ImageWidth', 'ImageHeight');
|
$info = $exifTool->GetInfo(\@ioTagList);
|
$info = $exifTool->GetInfo({Group2 => ['Author', 'Location']});
|
The following options are effective in the call to GetInfo:
Charset, CoordFormat, DateFormat, Duplicates, Exclude, Group#, Lang, List, ListSep,
StrictDate, PrintConv, Sort (if a tag list reference is given) and StrictDate.
Write meta information to a file. The specified source file is rewritten to the
same-type destination file with new information as specified by previous calls
to SetNewValue. The necessary segments and/or
directories are created in the destination file as required to store the
specified information. May be called repeatedly to write the same information
to additional files without the need to call
SetNewValue again.
Prototype | WriteInfo($$;$$) |
Inputs | 0) ExifTool object reference
1) Source file name, file reference, scalar reference, or undef to
create a file from scratch
2) [optional] Destination file name, file reference, scalar
reference, or undef to edit in place
3) [optional] Destination file type
|
Returns | 1 if file was written OK, 2 if file was written
but no changes made, 0 on file write error.
|
The source file name may be undefined to create a file from scratch
(currently only XMP, ICC and MIE files can be created in this way). If
undefined, the destination file type is required unless the type can be
determined from the destination file name.
If a destination file name is given, the specified file must not exist
because an existing destination file will not be overwritten. The
destination file name may be undefined to edit the source file in place
(make sure you have backups!). In this case, a temporary file is created
and renamed to replace the source file if no errors occurred while writing.
The destination file type is only used if the source file is undefined.
Examples:
# add information to a source file, writing output to new file
my $result = $exifTool->WriteInfo($srcfile, $dstfile);
|
# create XMP data file from scratch
$exifTool->WriteInfo(undef, $dstfile, 'XMP');
|
# edit file in place (you do have backups, right?)
$exifTool->WriteInfo($srcfile);
|
# retrieve error and warning messages
$errorMessage = $exifTool->GetValue('Error');
$warningMessage = $exifTool->GetValue('Warning');
|
If an error code is returned, an Error tag is set and GetValue('Error') can
be called to obtain the error description. A Warning tag may be set even if
this routine is successful.
The following ExifTool options are effective in the call to
WriteInfo:
ByteOrder, Charset, Compact, Compress, FixBase, IgnoreMinorErrors and Verbose.
Combine information from more than one information hash into a single hash.
Prototype | CombineInfo($;@) |
Inputs | 0) ExifTool object reference
1-N) List of info hash references
|
Returns | Reference to combined information hash |
Example:
$info = $exifTool->CombineInfo($info1, $info2, $info3);
|
If the Duplicates option is disabled and duplicate tags exist, the order of
the hashes is significant. In this case, the value used is the first value
found as the hashes are scanned in order of input. The Duplicates option
is the only option that is in effect for this function.
Get a sorted list of tags from the specified information hash or tag list.
Prototype | GetTagList($;$$) |
Inputs | 0) ExifTool object reference
1) [optional] Reference to info hash or tag list
2) [optional] Sort order ('File', 'Input', 'Alpha' or 'Group#')
|
Returns | List of tags in specified order |
Example:
@tags = $exifTool->GetTagList($info, 'Group0');
|
If the information hash or tag list reference is not provided, then the list
of found tags from the last call to ImageInfo,
ExtractInfo or GetInfo
is used instead, and the result is the same as if
GetFoundTags was called. If sort order is not
specified, the sort order is taken from the current options settings.
Get list of found tags in specified sort order. The found tags are the
tags for the information obtained from the most recent call to
ImageInfo, ExtractInfo
or GetInfo for this object.
Prototype | GetFoundTags($;$) |
Inputs | 0) ExifTool object reference
1) [optional] Sort order ('File', 'Input', 'Alpha' or 'Group#')
|
Returns | List of tag keys in the specified order |
Example:
my @tags = $exifTool->GetFoundTags('File');
|
Get list of requested tags. These are the tags that were specified
in the arguments of the most recent call to ImageInfo,
ExtractInfo or GetInfo,
including tags specified via a tag list reference. They are returned
in the same order that they were specified. Shortcut tags are expanded
in the list.
Prototype | GetRequestedTags($) |
Inputs | 0) ExifTool object reference
|
Returns | List of tag keys for requested tags
(empty if no tags specifically requested) |
Example:
my @requestedTags = $exifTool->GetRequestedTags();
|
Get the value of a specified tag. The returned value is either the
human-readable (PrintConv) value, the converted machine-readable (ValueConv)
value, or the original raw (Raw) value. If the value type is not specified,
the PrintConv value is returned if the PrintConv option is set, otherwise the
ValueConv value is returned. The PrintConv values are the same as the values
returned by ImageInfo and GetInfo
in the tag/value hash unless the PrintConv option is disabled.
Tags which represent lists of multiple values (as may happen with
'Keywords
' for example) are handled specially. In scalar context,
the returned PrintConv value for these tags is either a string of values or
a list reference (depending on the List option setting), and the ValueConv
value is always a list reference. But in list context,
GetValue always returns the list itself.
Prototype | GetValue($$;$) |
Inputs | 0) ExifTool object reference
1) Tag key
2) [optional] Value type, 'PrintConv', 'ValueConv', 'Both' or 'Raw'
The default value type is 'PrintConv' if the PrintConv option
is set, otherwise the default is 'ValueConv'. A value type of 'Both'
returns both ValueConv and PrintConv values as a list.
|
Returns |
The value of the specified tag. If the tag represents a list of values and
the List option is disabled then PrintConv returns a string of values,
otherwise a reference to the list is returned in scalar context. The list
itself is returned in list context. Values may also be scalar references to
binary data.
Note: It is possible for GetValue to return an
undefined ValueConv or PrintConv value (or an empty list in list context)
even if the tag exists, since it is possible for these conversions to yield
undefined values.
|
Examples:
# PrintConv example
my $val = $exifTool->GetValue($tag);
if (ref $val eq 'SCALAR') {
print "$tag = (unprintable value)\n";
} else {
print "$tag = $val\n";
}
|
# ValueConv example
my $val = $exifTool->GetValue($tag, 'ValueConv');
if (ref $val eq 'ARRAY') {
print "$tag is a list of values\n";
} elsif (ref $val eq 'SCALAR') {
print "$tag represents binary data\n";
} else {
print "$tag is a simple scalar\n";
}
|
# list example
my @keywords = $exifTool->GetValue('Keywords', 'ValueConv');
|
Set the new value for a tag. The routine may be called multiple times to set
the values of many tags before using WriteInfo to write
the new values to an image.
For list-type tags (like Keywords
), either call repeatedly with
the same tag name for each value, or call with a reference to the list of values.
Prototype | SetNewValue($;$$%) |
Inputs | 0) ExifTool object reference
1) [optional] Tag key or tag name, or undef to clear all
new values. A tag name of '* ' can be used when deleting tags to
delete all tags, or all tags in a specified group. The tag name may be
prefixed by group name, separated by a colon (ie. 'GROUP:TAG '),
which is equivalent to using a 'Group' option argument.
2) [optional] New value for tag. Undefined to delete tag from file.
May be a scalar, scalar reference, or list reference to set a list
of values.
3-N) [optional] SetNewValue options hash entries (see below).
|
Returns | Scalar context: The number of tags set, and
errors are printed to STDERR.
List context: The number of tags set and the error string.
|
SetNewValue Options |
Option | Description | Values | Default |
Type | The type of value being set |
PrintConv, ValueConv or Raw (default depends on PrintConv Option) |
PrintConv or ValueConv |
AddValue | Add value to existing list rather than
replacing the list | 0 or 1 | 0 |
DelValue | Delete an existing tag if it has the specified value |
0 or 1 | 0 |
Group | Specifies group name where tag should be written.
If not specified, tag is written to highest priority group as specified
by SetNewGroups. Case is not significant |
Any family 0 or 1 group name | undef |
NoShortcut | Disables default behaviour of looking up tag in
shortcuts if not found otherwise. | 0 or 1 | 0 |
Protected | Allow protected tags to be written |
Bitmask of tag protection levels to write:
| 0 |
Replace | Replace previous new value for this tag (ie. replace the value
set in a previous call to SetNewValue) |
0 = | Don't replace |
1 = | Replace with specified new value |
2 = | Reset previous new value only |
| 0 |
Shift | Shift the tag by the specified value. Currently only date/time
tags can be shifted. Value is added if Shift is 1, or subtracted if Shift is -1.
See Image::ExifTool::Shift.pl for details time shift formats. |
undef = No shift |
0 = | Shift if shiftable:
Positive if AddValue set, or
Negative if DelValue set |
1 = | Positive shift |
-1 = | Negative shift |
| undef |
Examples:
# set a new value for a tag (errors go to STDERR)
$success = $exifTool->SetNewValue($tag, $value);
|
# set a new value and capture any error message
($success, $errStr) = $exifTool->SetNewValue($tag, $value);
|
# delete information for specified tag if it exists in image
# (also resets AddValue and DelValue options for this tag)
$exifTool->SetNewValue($tag);
|
# reset all values from previous calls to SetNewValue()
$exifTool->SetNewValue();
|
# delete a specific keyword
$exifTool->SetNewValue('Keywords', $word, DelValue => 1);
|
# set keywords (a List-type tag) with two new values
$exifTool->SetNewValue(Keywords => 'word1');
$exifTool->SetNewValue(Keywords => 'word2');
# equivalent, but set both in one call using an array reference
$exifTool->SetNewValue(Keywords => ['word1','word2']);
|
# add a keyword without replacing existing keywords in the file
$exifTool->SetNewValue(Keywords => $word, AddValue => 1);
|
# set a tag in a specific group
$exifTool->SetNewValue(Headline => $val, Group => 'XMP');
$exifTool->SetNewValue('XMP:Headline' => $val); # equivalent
|
# shift original date/time back by 1 hour
$exifTool->SetNewValue(DateTimeOriginal => '1:00', Shift => -1);
|
# delete all but EXIF tags
$exifTool->SetNewValue('*'); # delete all...
$exifTool->SetNewValue('EXIF:*', undef, Replace => 2); # ...but EXIF
|
Notes:
When deleting groups of tags, the Replace option may be used as in the last
example above to exclude specific groups from a mass delete. However, this
technique may not be used to exclude individual tags. Instead, use
SetNewValuesFromFile to recover the values
of individual tags after deleting a group.
The following ExifTool options are effective in the call to
SetNewValue:
Charset, IgnoreMinorErrors, Lang, ListSep, ListSplit, PrintConv and Verbose.
A very powerful routine that sets new values for tags from information found
in a specified file.
Prototype | SetNewValuesFromFile($$;@) |
Inputs | 0) ExifTool object reference
1) File name, file reference, or scalar reference
2-N) [optional] List of tag names to set or options hash
references. All writable tags are set if none are specified. The tag
names are not case sensitive, and may be prefixed by an optional family 0
or 1 group name, separated by a colon (ie. 'exif:iso '). A
leading '- ' indicates tags to be excluded (ie.
'-comment '). An asterisk ('* ') may be used for
the tag name, and is useful when a group is specified to set all tags from
a group (ie. 'XMP:* ').
A special feature allows tag names of the form 'SRCTAG>DSTTAG '
(or 'DSTTAG<SRCTAG ') to be specified to copy information to a
tag with a different name or a specified group. Both 'SRCTAG ' and
'DSTTAG ' may use '* ' and/or be prefixed by a group
name (ie. 'modifyDate>fileModifyDate ' or
'*>xmp:* '). Copied tags may also be added or deleted from a
list with arguments of the form 'SRCTAG+>DSTTAG ' or
'SRCTAG->DSTTAG '. Tags are evaluated in order, so exclusions
apply only to tags included earlier in the list. An extension of this feature
allows the tag value to be set from an expression containing tag names with
leading '$ ' symbols (ie. 'Comment<Filename:
$filename '). Braces '{} ' may be used around the tag name to
separate it from subsequent text, and a '$$ ' is used to to
represent a '$ ' symbol. (The behaviour for missing tags in
expressions is defined by the MissingTagValue
option.)
Multiple options hash references may be passed to set different options for
different tags. Options apply to subsequent tags in the argument list.
|
Returns | A hash of information that was set
successfully. May include Warning or Error entries if there were problems
reading the input file.
|
By default, this routine will commute information between same-named tags in
different groups, allowing information to be translated between images with
different formats. This behaviour may be modified by specifying a group name
for extracted tags (even if '*
' is used as a group name), in which
case the information is written to the original group, unless redirected to a
different group. (For example, a tag name of '*:*
' may be
specified to copy all information while preserving the original groups.)
SetNewValuesFromFile Options:
The options are the same was for SetNewValue, and
are passed directly to SetNewValue internally,
with a few exceptions:
- The Replace option defaults to 1 instead of 0 as with
SetNewValue.
- The AddValue or DelValue option is set for individual tags if '+>' or
'->' (or '+<' or '-<') are used.
- The Group option is set for tags where a group name is given.
- The Protected flag is set to 1 for individually specified tags.
- The Type option also applies to extracted tags.
Examples:
# set new values from all information in a file...
my $info = $exifTool->SetNewValuesFromFile($srcFile);
# ...then write these values to another image
my $result = $exifTool->WriteInfo($file2, $outFile);
|
# set all new values, preserving original groups
$exifTool->SetNewValuesFromFile($srcFile, '*:*');
|
# set specific information
$exifTool->SetNewValuesFromFile($srcFile, $tag1, $tag2...);
|
# set new value from a different tag in specific group
$exifTool->SetNewValuesFromFile($src, 'IPTC:Keywords>XMP-dc:Subject');
|
# add all IPTC keywords to XMP subject list
$exifTool->SetNewValuesFromFile($src, 'IPTC:Keywords+>XMP-dc:Subject');
|
# set new value from an expression involving other tags
$exifTool->SetNewValuesFromFile($file,
'Comment<ISO=$ISO Aperture=$aperture Exposure=$shutterSpeed');
|
# set keywords list from the values of multiple tags
$exifTool->SetNewValuesFromFile($file, { Replace => 0 },
'keywords<xmp:subject', 'keywords<filename');
|
Notes:
The PrintConv option applies to this routine, but it normally should be left
on to provide more reliable transfer of information between groups.
If a preview image exists, it is not copied. The preview image must be
transferred separately if desired, in a separate call to
WriteInfo
When simply copying all information between files of the same type, it is
usually desirable to preserve the original groups by specifying
'*:*
' for the tags to set.
Get list of new Raw values for the specified tag. These are the values
that will be written to file. Only tags which support a 'List' may return
more than one value.
Prototype | GetNewValues($$) |
Inputs | 0) ExifTool object reference
1) Tag key or tag name
|
Returns | List of new Raw tag values.
The list may be empty if the tag is being deleted
(ie. if SetNewValue was called without a value).
|
Examples:
my $rawVal = $exifTool->GetNewValues($tag);
|
my @rawVals = $exifTool->GetNewValues($tag);
|
Return the total number of new values set.
Prototype | CountNewValues($) |
Inputs | 0) ExifTool object reference
|
Returns | In scalar context, returns the total number
of tags with new values set. In list context, also returns the number of
"pseudo" tag values which have been set. "Pseudo" tags are tags like FileName
and FileModifyDate which are not contained within the file and can be changed
without rewriting the file. |
Examples:
my $numSet = $exifTool->CountNewValues();
|
my ($numSet, $numPseudo) = $exifTool->CountNewValues();
|
Save state of new values to be later restored by RestoreNewValues.
Prototype | SaveNewValues($) |
Inputs | 0) ExifTool object reference
|
Example:
$exifTool->SaveNewValues(); # save state of new values
$exifTool->SetNewValue(ISO => 100); # set new value for ISO
$exifTool->WriteInfo($src, $dst1); # write ISO plus any previous new values
$exifTool->RestoreNewValues(); # restore previous new values
$exifTool->WriteInfo($src, $dst2); # write previous new values only
|
Restore new values to the settings that existed when
SaveNewValues was last called. May be called
repeatedly after a single call to SaveNewValues.
See SaveNewValues above for an example.
Prototype | RestoreNewValues($) |
Inputs | 0) ExifTool object reference
|
Set the file modification time from the new value of the FileModifyDate tag.
Prototype | SetFileModifyDate($$;$) |
Inputs | 0) ExifTool object reference
1) File name
2) [optional] Base time if applying shift (in days before $^T)
|
Returns | 1 if the time was changed, 0 if nothing was
done, or -1 if there was an error setting the time.
|
Example:
$exifTool->SetNewValue(FileModifyDate => '2000:01:02 03:04:05', Protected => 1);
my $result = $exifTool->SetFileModifyDate($file);
|
Notes:
Equivalent to, but more efficient than calling WriteInfo
when only the FileModifyDate tag has been set. If a timezone is not specified
in the FileModifyDate value, local time is assumed. When shifting
FileModifyDate, the time of the original file is used unless an optional base
time is specified.
Set the file name and directory. If not specified, the new file name is
derived from the new values of the FileName and Directory tags. If the FileName
tag contains a '/
', then the file is renamed into a new directory.
If FileName ends with '/
', then it is taken as a directory name and
the file is moved into the new directory. The new value for the Directory tag
takes precedence over any directory specified in FileName.
Prototype | SetFileName($$;$) |
Inputs | 0) ExifTool object reference
1) Current file name
2) [optional] New file name
|
Returns | 1 if the file name or directory was changed,
0 if nothing was done, or -1 if there was an error renaming the file.
|
Examples:
my $result = $exifTool->SetFileName($file);
|
my $result = $exifTool->SetFileName($file, $newName);
|
Notes:
Will not overwrite existing files. New directories are created as
necessary.
Set the order of the preferred groups when adding new information. In
subsequent calls to SetNewValue, new information
will be created in the first valid group of this list. This has an impact
only if the group is not specified when calling
SetNewValue, and if the tag name exists in more
than one group. The default order is EXIF, IPTC, XMP then MakerNotes. Any
family 0 group name may be used. Case is not significant.
Prototype | SetNewGroups($;@) |
Inputs | 0) ExifTool object reference
1-N) Groups in order of priority. If no groups are specified, the
priorities are reset to the defaults.
|
Example:
$exifTool->SetNewGroups('XMP','EXIF','IPTC');
|
Get current group priority list.
Prototype | GetNewGroups($) |
Inputs | 0) ExifTool object reference
|
Returns | List of group names in order of write
priority. Highest priority first.
|
Example:
@groups = $exifTool->GetNewGroups();
|
Get the ID for the specified tag. The ID is the IFD tag number in EXIF
information, the property name in XMP information, or the data offset in a
binary data block. For some tags, such as Composite tags where there is no ID,
an empty string is returned.
Prototype | GetTagID($$) |
Inputs | 0) ExifTool object reference
1) Tag key
|
Returns | Tag ID or '' of there is no ID for this tag |
Example:
my $id = $exifTool->GetTagID($tag);
|
Get description for specified tag. This function will always return a defined
value. In the case where the description doesn't exist, the tag name is returned.
Prototype | GetDescription($$) |
Inputs | 0) ExifTool object reference
1) Tag key
|
Returns | Tag description |
Get group name(s) for a specified tag.
Prototype | GetGroup($$;$) |
Inputs | 0) ExifTool object reference
1) Tag key
2) [optional] Group family number, or string of numbers
separated by colons
|
Returns | Group name (or '' if tag has no
group). If no group family is specified, returns the name of group in family 0
when called in scalar context, or the names of groups for all families in list
context. Returns a string of group names separated by colons if the input group
family contains a colon. The string is simplified to remove a leading 'Main:'
and adjacent identical group names unless the family string begins with a colon.
|
The following families of groups are available:
Family | Description | Examples |
0 | Information Type | EXIF, XMP, IPTC |
1 | Specific Location | IFD0, XMP-dc |
2 | Category | Author, Time |
3 | Document Number | Main, Doc1, Doc3-2 |
Families 0 and 1 are based on the file structure, and are similar except that
family 1 is more specific -- it sub-divides the EXIF, MakerNotes, XMP and
ICC_Profile groups to give more detail about the specific location where the
information was found. The EXIF group is split up based on the specific IFD
(Image File Directory), the MakerNotes group is divided into groups for each
manufacturer, and the XMP group is separated based on the XMP namespace prefix.
Note that only common XMP namespaces are listed below but additional namespaces
may be present in some XMP data. Also note that the 'XMP-xmp
...'
group names may appear in the older form 'XMP-xap
...' since these
names evolved as the XMP standard was developed. The ICC_Profile group is
broken down to give information about the specific ICC_Profile tag from which
multiple values were extracted. As well, information extracted from the
ICC_Profile header is separated into the ICC-header group.
Family 2 classifies information based on the logical category to which the
information refers.
Family 3 gives the document number when the
ExtractEmbedded option is used. Nested sub-documents (if
they exist) are indicated by numbers separated with dashes in the group name, to
an arbitrary depth. (ie. 'Doc2-3-1
' is the 1st
sub-sub-document of the 3rd sub-document of the 2nd
embedded document of the main file.)
See GetAllGroups for lists of group names.
Examples:
# return family 0 group name (ie. 'EXIF')
$group = $exifTool->GetGroup($tag, 0);
|
# return all groups (ie. qw{EXIF IFD0 Author Main})
@groups = $exifTool->GetGroup($tag);
|
# return groups as a string (ie. 'Main:IFD0:Author')
$group = $exifTool->GetGroup($tag, ':3:1:2');
|
# return groups as a simplified string (ie. 'IFD0:Author')
$group = $exifTool->GetGroup($tag, '3:1:2');
|
Get list of group names for all tags in specified information hash.
Prototype | GetGroups($;$$) |
Inputs | 0) ExifTool object reference
1) [optional] Information hash reference (default is all extracted info)
2) [optional] Group family number (default 0)
|
Returns |
List of group names in alphabetical order.
If information hash is not specified, the group names are returned for
all extracted information. See GetAllGroups for
a list of groups in each family.
|
Examples:
my @groups = $exifTool->GetGroups($info, $family);
|
Example of one way to print information organized by group
my $exifTool = new Image::ExifTool;
$exifTool->ExtractInfo('t/images/ExifTool.jpg');
my $family = 1;
my @groups = $exifTool->GetGroups($family);
my $group;
foreach $group (@groups) {
print "---- $group ----\n";
my $info = $exifTool->GetInfo({"Group$family" => $group});
foreach ($exifTool->GetTagList($info)) {
print "$_ : $$info{$_}\n";
}
}
|
Builds composite tags from required tags. The composite tags are convenience
tags which are derived from the values of other tags. This routine is called
automatically by ImageInfo if the Composite option is set.
Prototype | BuildCompositeTags($) |
Inputs | 0) ExifTool object reference
|
Returns | (none) |
Notes:
- Tag values are calculated in alphabetical order unless a tag Require's
or Desire's another composite tag, in which case the calculation is
deferred until after the other tag is calculated.
- Composite tags may need to read data from the image for their value to be
determined, so for these BuildCompositeTags
must be called while the image is available. This is only a problem if
ImageInfo is called with a filename (as opposed to a
file reference or scalar reference) since in this case the file is closed before
ImageInfo returns. However if you enable the Composite
option, BuildCompositeTags is called from
within ImageInfo before the file is closed.
The following functions access only static data and are not called with an
ExifTool object
|
The names of all the following functions, plus
ImageInfo, may be imported into the current namespace
with the "Public" tag. When this is done, the functions can be accessed without
the need to prefix the function name with "Image::ExifTool::
". For
example:
use Image::ExifTool ':Public';
$tagName = GetTagName($tag);
|
Get name of tag from tag identifier. This is a convenience function that
strips the embedded instance number, if it exists, from the tag key.
Prototype | GetTagName($) |
Inputs | 0) Tag key
|
Returns | Tag name |
Example:
$tagName = Image::ExifTool::GetTagName($tag);
|
Get list of tag shortcut names.
Prototype | GetShortcuts() |
Inputs | (none)
|
Returns | List of shortcuts |
Get list of all available tag names.
Prototype | GetAllTags(;$) |
Inputs | 0) [optional] Group name,
or string of group names separated by colons
|
Returns | A list of all available tags in alphabetical
order, or all tags in a specified group or intersection of groups. The
group name is case insensitive, and any group in families 0-2 may be used
except for EXIF family 1 groups (ie. the specific IFD).
|
Get list of all writable tag names.
Prototype | GetWritableTags(;$) |
Inputs | 0) [optional] Group name,
or string of group names separated by colons
|
Returns | A list of all writable tags in alphabetical
order. These are the tags for which values may be set through
SetNewValue. If a group name is given, returns
only writable tags in specified group(s). The group name is case insensitive,
and any group in families 0-2 may be used except for EXIF family 1 groups (ie.
the specific IFD).
|
Get list of all group names in specified family.
Prototype | GetAllGroups($) |
Inputs | 0) Group family number (0-3)
|
Returns |
A list of all groups in the specified family in alphabetical order |
Here is a complete list of groups for each family:
Family | Group Names |
0 (Information Type) |
AFCP, AIFF, APE, APP12, APP13, APP14, APP15, APP5, APP6, APP8, ASF, BMP,
CanonVRD, Composite, DICOM, DNG, DjVu, Ducky, EXE, EXIF, ExifTool, FLAC,
File, Flash, FlashPix, FotoStation, GeoTiff, HTML, ICC_Profile, ID3, IPTC,
ITC, JFIF, JPEG, Jpeg2000, Leaf, MIE, MIFF, MNG, MPC, MPEG, MakerNotes,
Meta, PDF, PICT, PNG, PhotoMechanic, Photoshop PostScript, PrintIM,
QuickTime, RAF, RIFF, Rawzor, Real, Ricoh, SVG, SigmaRaw, Vorbis, XMP, ZIP
|
1 (Specific Location) |
AFCP, AIFF, APE, ASF, Adobe, AdobeCM, BMP, Canon, CanonCustom, CanonRaw,
CanonVRD, Casio, Composite, DICOM, DNG, DjVu, DjVu-Meta, Ducky, EPPIM, EXE,
EXIF, ExifIFD, ExifTool, FLAC, File, Flash, FlashPix, FotoStation, FujiFilm,
GPS, GeoTiff, GlobParamIFD, GraphConv, HP, HTML, HTML-dc, HTML-ncc,
HTML-prod, HTML-vw96, HTTP-equiv, ICC-chrm, ICC-clrt, ICC-header, ICC-meas,
ICC-view, ICC_Profile, ICC_Profile#, ID3, ID3v1, ID3v2_2, ID3v2_3, ID3v2_4,
IFD0, IFD1, IPTC, IPTC#, ITC, InteropIFD, JFIF, JPEG, JVC, Jpeg2000, Kodak,
KodakBordersIFD, KodakEffectsIFD, KodakIFD, KyoceraRaw, Leaf, LeafSubIFD,
Leica, MAC, MIE-Audio, MIE-Camera, MIE-Canon, MIE-Doc, MIE-Extender,
MIE-Flash, MIE-GPS, MIE-Geo, MIE-Image, MIE-Lens, MIE-Main, MIE-MakerNotes,
MIE-Meta, MIE-Orient, MIE-Preview, MIE-Test, MIE-Thumbnail, MIE-UTM,
MIE-Unknown, MIE-Video, MIFF, MNG, MPC, MPEG, MakerNotes, MakerUnknown,
MetaIFD, Minolta, MinoltaRaw, Nikon, NikonCapture, NikonPreview, NikonScan,
Olympus, PDF, PICT, PNG, Panasonic, Pentax, PhotoMechanic, Photoshop,
PictureInfo, PostScript, PrintIM, ProfileIFD, QuickTime, RAF, RAF2, RIFF,
RMETA, Rawzor, Real, Real-CONT, Real-MDPR, Real-PROP, Real-RA3, Real-RA4,
Real-RA5, Real-RJMD, Ricoh, SPIFF, SR2, SR2DataIFD, SR2SubIFD, SRF#, SVG,
Sanyo, Sigma, SigmaRaw, Sony, SubIFD, Track#, Vorbis, XMP, XMP-DICOM,
XMP-PixelLive, XMP-acdsee, XMP-album, XMP-aux, XMP-cc, XMP-crs, XMP-dc,
XMP-dex, XMP-exif, XMP-iptcCore, XMP-iptcExt, XMP-lr, XMP-mediapro,
XMP-microsoft, XMP-pdf, XMP-photomech, XMP-photoshop, XMP-plus, XMP-prism,
XMP-prl, XMP-pur, XMP-rdf, XMP-tiff, XMP-x, XMP-xmp, XMP-xmpBJ, XMP-xmpDM,
XMP-xmpMM, XMP-xmpNote, XMP-xmpPLUS, XMP-xmpRights, XMP-xmpTPg, ZIP
|
2 (Category) |
Audio, Author, Camera, Document, ExifTool, Image, Location, Other, Printing,
Time, Unknown, Video
|
3 (Document Number) |
Doc#, Main
|
Example:
@groupList = Image::ExifTool::GetAllGroups($family);
|
Get list of all deletable group names.
Prototype | GetDelGroups() |
Inputs |
None
|
Returns | A list of deletable group names in
alphabetical order.
|
Below is a current list of deletable group names. All names in this list
are either family 0 or family 1 group names, with the exception of
'Trailer
' which allows all trailers in JPEG and TIFF-format images
to be deleted at once, including unknown trailers. To schedule a group for
deletion, call SetNewValue with an undefined value
and a tag name like 'Trailer:*
'.
AFCP, CIFF, CanonVRD, EXIF, ExifIFD, Ducky, File, FlashPix,
FotoStation, GlobParamIFD, GPS, IFD0, IFD1, InteropIFD, ICC_Profile, IPTC,
JFIF, MakerNotes, Meta, MetaIFD, MIE, PhotoMechanic, Photoshop, PNG,
PrintIM, RMETA, SubIFD, Trailer, XMP
Example:
my @delGroups = Image::ExifTool::GetDelGroups();
|
Get type of file given file name.
Prototype | GetFileType(;$$) |
Inputs |
0) [optional] File name (or just an extension)
1) [optional] Flag to return a description instead of a type
|
Returns | A string, based on the file extension, which
represents the type of file (or a description of the file type). Returns
undefined if the file type isn't supported by ExifTool. In array context,
may return more than one file type if the file may be different formats.
With no arguments, returns a list of extensions for all recognized file types.
|
Examples:
my $type = Image::ExifTool::GetFileType($filename);
my $desc = Image::ExifTool::GetFileType($filename, 1);
|
Can the specified file or file type be written?
Prototype | CanWrite($) |
Inputs |
0) File name, file extension, or file type |
Returns | True if the file type can be
written (edited). |
Example:
my $writable = Image::ExifTool::CanWrite($filename);
|
Can the specified file or file type be created?
Prototype | CanCreate($) |
Inputs |
0) File name, file extension, or file type |
Returns | True if the file type can be created
from scratch. Currently, this can only be done with XMP, MIE, ICC,
VRD and EXIF files. |
Example:
my $creatable = Image::ExifTool::CanCreate($filename);
|
<-- Back to ExifTool home page