-
Notifications
You must be signed in to change notification settings - Fork 1
/
description2exif.pl
executable file
·67 lines (60 loc) · 1.56 KB
/
description2exif.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/perl
#
# Read a descript.ion file (filename[whitespace]caption
# and insert the found value into the appropriate jpeg
# using exiftool
#
# dman 2009-12
use strict;
use Image::ExifTool ':Public';
my $exifTool = new Image::ExifTool;
my ($file) = @ARGV;
if (! -e "$file") {
$file = 'descript.ion';
}
if (! -e $file) {
die ("Missing input file. Needs a descript.ion file in the current dir");
}
my $recordCount = 0;
my $charCount = 0;
my $totalCount = 0;
open(IN, "< $file");
while (<IN>) {
$recordCount++;
my($filename, $description);
if ($_ =~ m/^\"([^\"]+)\" (.*)$/ ) {
$filename = $1; $description = $2;
}
elsif ($_ =~ m/^([^\"]\S+) (.*)$/ ) {
$filename = $1; $description = $2;
}
else {
print("NO MATCH $_\n");
}
# OK, now insert that tag into that file
if ( -e $filename ) {
print("Adding tag to [$filename] = $description\n");
#my $info = $exifTool->ImageInfo($filename);
# dump current data
#foreach (keys %$info) {
# print "$_ => $$info{$_}\n";
#}
$exifTool->SetNewValue(Description => $description);
my ($title, $discard) = split(/\./, $filename);
if ("$title") {
$title =~ s/\d\d\.\d\d\.\d\d //;
print("Adding tag to [$filename] Title = $title\n");
$exifTool->SetNewValue(Title => $title);
}
else {
print("No title\n");
}
$exifTool->WriteInfo($filename);
}
else {
#print("File [$filename] not found, skipping\n");
}
}
close(IN);
print "Number of records = $recordCount\n";
exit;