2
# @(#$Id: rclimg,v 1.5 2008-10-09 06:41:21 dockes Exp $ (C) 2007 Cedric Scott
3
#######################################################
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the
16
# Free Software Foundation, Inc.,
17
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
######################################################
21
# Extract image tags with exiftool and convert the data to html for
26
# maps image file tags to xapian tags
29
'subject' => 'subject',
31
'headline' => 'title',
32
'caption' => 'caption',
33
'caption-abstract' => 'caption',
35
'creator' => 'creator',
37
'keywords' => 'keywords',
38
'keyword' => 'keyword',
42
# set to non-zero if tags which map to xapian tags are to output
43
# in the body as well as the header
48
# returns a xapian tag to be used for this tag
52
while ( ( $tagre, $xapiantag) = each %{$tagMap} ) {
53
return $xapiantag if $imgtag =~ /$tagre/i;
59
my $imageFile = shift;
61
$imageFile = '-' if $imageFile eq '';
62
unless ( open(IMGF, $imageFile) ) {
63
print STDERR "$0: can't open file $imageFile\n";
64
return $output; # file doesn't exist or can't be read
66
$info = ImageInfo(\*IMGF);
67
return $output unless $info;
71
foreach $tagname ( sort keys %{$info} ) {
72
$xapiantag = xapianTag($tagname);
73
if (defined $xapiantag ) {
74
push @{$fields}, [ $xapiantag, $info->{$tagname} ];
75
if ($xapiantag eq 'title') {
76
$titleHtmlTag = "<title>$info->{$tagname}</title>";
78
push @{$other}, [ $tagname, $info->{$tagname} ] if $headAndBody;
80
push @{$other}, [ $tagname, $info->{$tagname} ];
83
$output = "<html>\n<head>\n$titleHtmlTag\n" .
84
"<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">\n";
85
foreach $tagpair ( @{$fields} ) {
86
($tagname, $value) = @{$tagpair};
87
$output = $output . "<meta name=\"$tagname\" content=\"$value\">\n";
89
$output = $output . "</head><body>\n";
90
foreach $tagpair (@{$other} ) {
91
($tagname, $value) = @{$tagpair};
92
$output = $output . sprintf("%30s : %s<br>\n", $tagname, $value);
94
$output = $output . "</body>\n</html>\n";
98
# Get one line from stdin (from recollindex), exit on eof
102
# print STDERR "RCLIMG: EOF\n";
108
# Read one named parameter
110
my $s = readlineorexit();
114
my @l = split(' ', $s);
116
if (scalar(@l) != 2) {
117
print STDERR "RCLIMG: bad line:", $s;
120
my $paramname = lc $l[0];
121
my $paramsize = $l[1];
122
if ($paramsize > 0) {
123
my $n = read STDIN, $paramdata, $paramsize;
124
if ($n != $paramsize) {
125
print STDERR "RCLIMG: [$paramname] expected $paramsize, got $n\n";
129
# print STDERR "RCLIMG: [$paramname] $paramsize bytes: [$paramdata]\n";
130
return ($paramname, $paramdata);
134
# Main program starts here. Talks the rclexecm protocol
137
# JFD: replaced the "use" call with a runtime load with error checking,
138
# for compat with the missing filter detection code.
139
#use Image::ExifTool qw(:Public);
140
eval {require Image::ExifTool; Image::ExifTool->import(qw(:Public));};
142
print "RECFILTERROR HELPERNOTFOUND Perl::Image::ExifTool\n";
146
#print STDERR "RCLIMG: Starting\n";
149
# print STDERR "RCLIMG: waiting for command\n";
152
# Read at most 10 parameters (we only actually use one), stop at empty line
153
for($i = 1; $i < 10; $i++) {
154
my ($name, $value) = readparam;
158
$params{$name} = $value;
160
unless (defined $params{"filename:"}) {
161
print STDERR "RCLIMG: no filename ??\n";
162
# Recoll is requesting next subdocument (it shouldn't cause we
163
# returned eofnext last time), but we have none, just say so:
164
print "Eofnow:0\nDocument: 0\n\n";
168
print "Mimetype: 9\ntext/html";
169
my $data = imgTagsToHtml($params{"filename:"});
170
my $l = length($data);
171
print "Document: $l\n";
172
# print STDERR "RCLIMG: writing $l bytes of data\n";
174
# Say we have no further documents for this file
175
print "Eofnext: 0\n";
176
# End of output parameters: print empty line
178
# print STDERR "RCLIMG: done writing data\n";
180
#print STDERR "RCLIMG: Exiting\n";