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

Last change on this file since 21240 was 21240, checked in by kjdon, 14 years ago

use the new PharosImageIndexer plugin

  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 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 BasePlugin;
29use ImageConverter;
30use PharosImageIndexer;
31
32use strict;
33no strict 'refs'; # allow filehandles to be variables and viceversa
34no strict 'subs';
35
36use gsprintf 'gsprintf';
37
38sub BEGIN {
39 @ImagePlugin::ISA = ('BasePlugin', 'ImageConverter', 'PharosImageIndexer');
40}
41
42my $arguments =
43 [ { 'name' => "process_exp",
44 'desc' => "{BasePlugin.process_exp}",
45 'type' => "regexp",
46 'deft' => &get_default_process_exp(),
47 'reqd' => "no" },
48 ];
49
50my $options = { 'name' => "ImagePlugin",
51 'desc' => "{ImagePlugin.desc}",
52 'abstract' => "no",
53 'inherits' => "yes",
54 'args' => $arguments };
55
56
57
58sub new {
59 my ($class) = shift (@_);
60 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
61 push(@$pluginlist, $class);
62
63 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
64 push(@{$hashArgOptLists->{"OptList"}},$options);
65
66
67 new ImageConverter($pluginlist, $inputargs, $hashArgOptLists);
68 new PharosImageIndexer($pluginlist, $inputargs, $hashArgOptLists);
69 my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
70
71 return bless $self, $class;
72}
73
74sub init {
75 my $self = shift (@_);
76 my ($verbosity, $outhandle, $failhandle) = @_;
77
78 $self->SUPER::init(@_);
79 $self->ImageConverter::init();
80 $self->PharosImageIndexer::init();
81 $self->{'cover_image'} = 0; # makes no sense for images
82}
83
84sub begin {
85 my $self = shift (@_);
86 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
87
88 $self->SUPER::begin(@_);
89 $self->ImageConverter::begin(@_);
90 $self->PharosImageIndexer::begin(@_);
91}
92
93sub get_default_process_exp {
94 my $self = shift (@_);
95
96 # from .jpf and onwards below, the file extensions are for JPEG2000
97 return q^(?i)(\.jpe?g|\.gif|\.png|\.bmp|\.xbm|\.tif?f|\.jpf|\.jpx|\.jp2|\.jpc|\.j2k|\.pnm|\.pgx)$^;
98}
99
100# this makes no sense for images
101sub block_cover_image
102{
103 my $self =shift (@_);
104 my ($filename) = @_;
105
106 return;
107}
108
109# do plugin specific processing of doc_obj
110sub process {
111 my $self = shift (@_);
112 # options??
113 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
114
115
116 my $outhandle = $self->{'outhandle'};
117 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
118
119 if ($self->{'image_conversion_available'} == 1)
120 {
121 my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
122 my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
123 $self->generate_images($filename_full_path, $url_encoded_filename, $doc_obj, $doc_obj->get_top_section()); # should we check the return value?
124 }
125 else
126 {
127 if ($gli) {
128 &gsprintf(STDERR, "<Warning p='ImagePlugin' r='{ImageConverter.noconversionavailable}: {ImageConverter.".$self->{'no_image_conversion_reason'}."}'>");
129 }
130 # all we do is add the original image as an associated file, and set up srclink etc
131 my $assoc_file = $doc_obj->get_assocfile_from_sourcefile();
132 my $section = $doc_obj->get_top_section();
133
134 $doc_obj->associate_file($filename_full_path, $assoc_file, "", $section);
135
136 $doc_obj->add_metadata ($section, "srclink", "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">");
137 $doc_obj->add_metadata ($section, "/srclink", "</a>");
138 # We don't know the size of the image, but the browser should display it at full size
139 $doc_obj->add_metadata ($section, "srcicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">");
140
141 # Add a fake thumbnail icon with the full-sized image scaled down by the browser
142 $doc_obj->add_metadata ($section, "thumbicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\" width=\"" . $self->{'thumbnailsize'} . "\">");
143 }
144 #we have no text - adds dummy text and NoText metadata
145 $self->add_dummy_text($doc_obj, $doc_obj->get_top_section());
146
147 return 1;
148
149}
150
151sub post_process_doc_obj {
152 my $self = shift (@_);
153 # options??
154 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
155 if ($self->{'enable_pharos_imageis'}) {
156 $self->pharos_index_image(&util::filename_cat($base_dir, $file), $doc_obj);
157 }
158}
159
160sub clean_up_after_doc_obj_processing {
161 my $self = shift(@_);
162
163 $self->ImageConverter::clean_up_temporary_files();
164}
165
1661;
167
168
169
170
171
172
173
174
175
176
177
Note: See TracBrowser for help on using the repository browser.