source: main/trunk/greenstone2/perllib/plugins/ImagePlugin.pm@ 36271

Last change on this file since 36271 was 36271, checked in by davidb, 3 months ago

Check for any sign of text being bound to the doc, before going ahead with the 'dummy text' hack originally added in for mg

  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1###########################################################################
2#
3# ImagePlugin.pm -- for processing standalone images
4# A component of the Greenstone digital library software
5# from the New Zealand Digital Library Project at the
6# University of Waikato, New Zealand.
7#
8# Copyright (C) 1999 New Zealand Digital Library Project
9#
10# This program is free software; you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation; either version 2 of the License, or
13# (at your option) any later version.
14#
15# This program is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18# GNU General Public License for more details.
19#
20# You should have received a copy of the GNU General Public License
21# along with this program; if not, write to the Free Software
22# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23#
24###########################################################################
25
26package ImagePlugin;
27
28use BaseImporter;
29use ImageConverter;
30
31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
33no strict 'subs';
34
35use gsprintf 'gsprintf';
36
37sub BEGIN {
38 @ImagePlugin::ISA = ('BaseImporter', 'ImageConverter');
39}
40
41my $arguments =
42 [ { 'name' => "process_exp",
43 'desc' => "{BaseImporter.process_exp}",
44 'type' => "regexp",
45 'deft' => &get_default_process_exp(),
46 'reqd' => "no" },
47 ];
48
49my $options = { 'name' => "ImagePlugin",
50 'desc' => "{ImagePlugin.desc}",
51 'abstract' => "no",
52 'inherits' => "yes",
53 'args' => $arguments };
54
55
56
57sub new {
58 my ($class) = shift (@_);
59 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
60 push(@$pluginlist, $class);
61
62 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
63 push(@{$hashArgOptLists->{"OptList"}},$options);
64
65
66 new ImageConverter($pluginlist, $inputargs, $hashArgOptLists);
67 my $self = new BaseImporter($pluginlist, $inputargs, $hashArgOptLists);
68
69 return bless $self, $class;
70}
71
72sub init {
73 my $self = shift (@_);
74 my ($verbosity, $outhandle, $failhandle) = @_;
75
76 $self->SUPER::init(@_);
77 $self->ImageConverter::init();
78 $self->{'cover_image'} = 0; # makes no sense for images
79}
80
81sub begin {
82 my $self = shift (@_);
83 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
84
85 $self->SUPER::begin(@_);
86 $self->ImageConverter::begin(@_);
87}
88
89
90sub get_default_process_exp {
91 my $self = shift (@_);
92
93 # from .jpf and onwards below, the file extensions are for JPEG2000
94 return q^(?i)\.(jpe?g|gif|png|bmp|xbm|tif?f|jpf|jpx|jp2|jpc|j2k|pnm|pgx)$^;
95}
96
97# this makes no sense for images
98sub block_cover_image
99{
100 my $self =shift (@_);
101 my ($filename) = @_;
102
103 return;
104}
105
106# do plugin specific processing of doc_obj
107sub process {
108 my $self = shift (@_);
109 # options??
110 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
111
112 my $outhandle = $self->{'outhandle'};
113 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
114
115 if ($self->{'image_conversion_available'} == 1)
116 {
117 my $plugin_filename_encoding = $self->{'filename_encoding'};
118 my $filename_encoding = $self->deduce_filename_encoding($file,$metadata,$plugin_filename_encoding);
119
120 my $url_encoded_full_filename
121 = &unicode::raw_filename_to_url_encoded($filename_full_path);
122
123 # should we check the return value?
124 $self->generate_images($filename_full_path,
125 $url_encoded_full_filename,
126 $doc_obj, $doc_obj->get_top_section(),$filename_encoding);
127
128 }
129 else
130 {
131 if ($gli) {
132 &gsprintf(STDERR, "<Warning p='ImagePlugin' r='{ImageConverter.noconversionavailable}: {ImageConverter.".$self->{'no_image_conversion_reason'}."}'>");
133 }
134 # all we do is add the original image as an associated file, and set up srclink etc
135 my $assoc_file = $doc_obj->get_assocfile_from_sourcefile();
136 my $section = $doc_obj->get_top_section();
137
138 $doc_obj->associate_file($filename_full_path, $assoc_file, "", $section);
139
140 # srclink_file is now deprecated because of the "_" in the metadataname. Use srclinkFile
141 $doc_obj->add_metadata ($section, "srclink_file", $doc_obj->get_sourcefile());
142 $doc_obj->add_metadata ($section, "srclinkFile", $doc_obj->get_sourcefile());
143 # We don't know the size of the image, but the browser should display it at full size
144 $doc_obj->add_metadata ($section, "srcicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[srclinkFile]\">");
145
146 # Add a fake thumbnail icon with the full-sized image scaled down by the browser
147 $doc_obj->add_metadata ($section, "thumbicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[srclinkFile]\" alt=\"[srclinkFile]\" width=\"" . $self->{'thumbnailsize'} . "\">");
148 }
149
150 # A plugin inheriting from this might be able to derive text from the image
151 # (e.g., through GoogleVisionAPI), and so don't just assume there is no
152 # text for the image -- check it's text length, and only set the dummy
153 # text if it is zero
154 if ($doc_obj->get_total_text_length() == 0) {
155 #we have no text - adds dummy text and NoText metadata
156 $self->add_dummy_text($doc_obj, $doc_obj->get_top_section());
157 }
158
159 return 1;
160
161}
162
163
164sub clean_up_after_doc_obj_processing {
165 my $self = shift(@_);
166
167 $self->ImageConverter::clean_up_temporary_files();
168}
169
1701;
171
172
173
174
175
176
177
178
179
180
181
Note: See TracBrowser for help on using the repository browser.