Difference between revisions of "ReNamer:Scripts:Exiv2"

From den4b Wiki
Jump to navigation Jump to search
(→‎Code: source tag)
(Updated script to ReNamer 5.70 and Exiv 0.23)
Line 2: Line 2:
  
 
== Requirements ==
 
== Requirements ==
* ReNamer v5.20 Beta
+
* ReNamer v5.70
* [http://www.exiv2.org/download.html exiv2.exe] v0.16 in ReNamer's folder
+
* [http://www.exiv2.org/download.html exiv2.exe] v0.23 in ReNamer's folder
  
 
== Code ==
 
== Code ==
  
Author: Denis Kozlov. Date: 10 Mar 2008. Extract unformatted line out of the command line output of the exiv2.exe tool. At the moment, this script extracts image timestamp. Adjust EXIV and TAG constants to extract other tags.
+
Author: Denis Kozlov. Date: 2013-04-01. Extract unformatted line out of the command line output of the <code>exiv2.exe</code> tool. This script extracts ''Image Timestamp''. Adjust <code>EXIV</code> and <code>TAG</code> constants to extract other tags.
 +
 
 +
'''Hint:''' ''Image Timestamp'' value is usually formatted as "yyyy:mm:dd hh:mm:ss" which contains an illegal filename character ":". The illegal character can be easily replaced using an additional Replace rule.
  
 
<source>
 
<source>
{ Insert EXIF/IPTC/XMP tags from images }
+
{ Extract EXIF/IPTC/XMP tags using Exiv2 }
 
+
 
const
 
const
   EXIV = '"exiv2.exe"';
+
   EXE = 'exiv2.exe';
 
   TAG = 'Image timestamp\s*\:\s*(.*?)[\r\n]';
 
   TAG = 'Image timestamp\s*\:\s*(.*?)[\r\n]';
 
+
 
var
 
var
 
   Command, Output: String;
 
   Command, Output: String;
 
   Matches: TStringsArray;   
 
   Matches: TStringsArray;   
 
+
 
begin
 
begin
   Command := EXIV+' "'+FilePath+'"';
+
   Command := EXE+' "'+FilePath+'"';
 
   if ExecConsoleApp(Command, Output) = 0 then
 
   if ExecConsoleApp(Command, Output) = 0 then
 
   begin
 
   begin
Line 31: Line 33:
 
</source>
 
</source>
  
For example, to extract IPTC Headline tag, you would need to make following changes:
+
To extract ''IPTC Headline'' tag, you would need to make following changes:
 
<source>
 
<source>
EXIV = '"exiv2.exe" -pi';
+
EXE = 'exiv2.exe -pi';
 
TAG = 'Iptc.Application2.Headline\s*\w*\s*\d*\s*(.*?)[\r\n]';
 
TAG = 'Iptc.Application2.Headline\s*\w*\s*\d*\s*(.*?)[\r\n]';
 
</source>
 
</source>

Revision as of 13:50, 1 April 2013

Script integrates Exiv2 library in order to extract EXIF/IPTC/XMP tags from many types of images. CRW, CR2, RAW images are also supported.

Requirements

  • ReNamer v5.70
  • exiv2.exe v0.23 in ReNamer's folder

Code

Author: Denis Kozlov. Date: 2013-04-01. Extract unformatted line out of the command line output of the exiv2.exe tool. This script extracts Image Timestamp. Adjust EXIV and TAG constants to extract other tags.

Hint: Image Timestamp value is usually formatted as "yyyy:mm:dd hh:mm:ss" which contains an illegal filename character ":". The illegal character can be easily replaced using an additional Replace rule.

{ Extract EXIF/IPTC/XMP tags using Exiv2 }
 
const
  EXE = 'exiv2.exe';
  TAG = 'Image timestamp\s*\:\s*(.*?)[\r\n]';
 
var
  Command, Output: String;
  Matches: TStringsArray;  
 
begin
  Command := EXE+' "'+FilePath+'"';
  if ExecConsoleApp(Command, Output) = 0 then
  begin
    Matches := SubMatchesRegEx(Output, TAG, False);
    if Length(Matches) > 0 then
      FileName := Matches[0] + WideExtractFileExt(FileName);
  end;
end.

To extract IPTC Headline tag, you would need to make following changes:

EXE = 'exiv2.exe -pi';
TAG = 'Iptc.Application2.Headline\s*\w*\s*\d*\s*(.*?)[\r\n]';