-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathexif.pl
executable file
·126 lines (125 loc) · 3.2 KB
/
exif.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/perl
#This is used to extract EXIF data out of any file and return the results in XML format - easy to read into PHP
if($ENV{HTTP_HOST}){print "Content-type: text/xml\n\n";}
require "$progpath/subs_common.pl";
use CGI qw(:cgi-lib redirect);
use Image::ExifTool;
#################################################################
### Read in input hash
my $cgi = new CGI;
my %input = $cgi->Vars;
$input{keywords}=undef;
#lowercase the input keys
foreach my $key (keys(%input)){
my $lkey=lc($key);
if(!defined $input{$lkey}){
$input{$lkey}=$input{$key};
delete($input{$key});
}
}
if(!$input{file}){
$input{file} = shift;
#read any other inputs into
while(1){
$arg = shift;
if(!defined $arg || !length($arg)){
last;
}
my($k,$v)=split(/\=/,$arg,2);
$input{$k}=$v;
}
if(!$input{file}){
print "ERROR: No File specified";
exit(1);
}
}
my $keycount=0;
foreach my $k(keys(%input)){
my $v=$input{$k};
if(length($v)){
#print "key:$k = $v\r\n";
$keycount++;
}
}
if(!-e $input{file}){
print "ERROR: No such file: " . $input{file};
exit(1);
}
if(!-s $input{file}){
print "ERROR: Empty file: " . $input{file};
exit(1);
}
my $afile=$input{file};
my $exifTool = new Image::ExifTool;
$exifTool->Options(Unknown => 1, WriteMode => 'wcg');
if($keycount > 1){
#write exif
$exifTool->ExtractInfo($afile);
$exifTool->SetNewValue('Make'); # Deleting this tag magically makes it work
foreach my $k (keys(%input)){
my $v=$input{$k};
print "key:$k = $v\r\n";
if($k ne 'file' && length($v)){
print "Writing to file:$k = $v \r\n";
my $success = $exifTool->SetNewValue($k,$v);
}
}
$success = $exifTool->WriteInfo($afile);
if($success){
print "Changes saved\r\n";
}
}
print "<root>\r\n";
print " <_input>\r\n";
print " <file>".$input{file}."</file>\r\n";
print " <name>".getFileName($input{file})."</name>\r\n";
print " <path>".getFilePath($input{file})."</path>\r\n";
print " <keycount>".$keycount."</keycount>\r\n";
print " </_input>\r\n";
my $info = $exifTool->ImageInfo($afile);
my $tag;
my %exif=();
foreach $tag ($exifTool->GetFoundTags('Group0')) {
my $group = strip($exifTool->GetGroup($tag));
my $val = $info->{$tag};
#clean up binary data
next if ref $val eq 'SCALAR';
$tag=strip($tag);
$tag=~s/\([0-9]+\)$//s;
$exif{$group}{$tag}=$val;
}
foreach my $group (sort(keys(%exif))){
$group=xmlEncodeCDATA($group);
print " <$group>\n";
foreach my $key (sort(keys(%{$exif{$group}}))){
$val=$exif{$group}{$key};
$val=xmlEncodeCDATA($val);
print " <$key>".$val."</$key>\r\n";
}
print " </$group>\r\n";
}
print "</root>\r\n";
#############
BEGIN {
#add path to INC
my @parts=split(/\:/,$ENV{PATH});
foreach $part (@parts){
unshift(@INC,$part);
}
$temp_dir = ( $ENV{TEMP} || $ENV{TMP} || $ENV{WINDIR} || '/tmp' ) . "/p2xtmp-$$";
$0 = $^X unless ($^X =~ m%(^|[/\\])(perl)|(perl.exe)$%i);
($progpath) = $0 =~ m%^(.*)[/\\]%;
$progpath ||= ".";
unshift(@INC,$progpath);
$progname=lc($0);
if($progname=~/[\/\\]/){
my @stmp=split(/[\/\\]/,$progname);
$progname=pop(@stmp);
}
$progname=~s/\Q$progpath\E//s;
$progname=~s/^[\\\/]+//s;
if($progname=~/(.+?)\.(exe|pl|so)/is){$progname=$1;}
if ($^X =~ /(perl)|(perl\.exe)$/i) {
$progexe=$progname . '.pl';
}
}