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

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

srclink now generated dynamically at runtime. instead of storing srclink metadata, we store srclink_file metadata, which can be a value (doc.doc) or a metadata format element (eg [SourceFile]).

  • Property svn:keywords set to Author Date Id Revision
File size: 4.9 KB
RevLine 
[1733]1###########################################################################
2#
[16820]3# ImagePlugin.pm -- for processing standalone images
[1733]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
[15872]26package ImagePlugin;
[1733]27
[15872]28use BasePlugin;
29use ImageConverter;
[1733]30
[10254]31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
[16856]33no strict 'subs';
[10254]34
[16856]35use gsprintf 'gsprintf';
36
[1733]37sub BEGIN {
[21287]38 @ImagePlugin::ISA = ('BasePlugin', 'ImageConverter');
[1733]39}
40
[4744]41my $arguments =
42 [ { 'name' => "process_exp",
[15872]43 'desc' => "{BasePlugin.process_exp}",
[6408]44 'type' => "regexp",
[4744]45 'deft' => &get_default_process_exp(),
46 'reqd' => "no" },
[15872]47 ];
[1758]48
[15872]49my $options = { 'name' => "ImagePlugin",
50 'desc' => "{ImagePlugin.desc}",
[6408]51 'abstract' => "no",
[3540]52 'inherits' => "yes",
53 'args' => $arguments };
54
55
[1744]56
[1733]57sub new {
[10218]58 my ($class) = shift (@_);
59 my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
60 push(@$pluginlist, $class);
[4724]61
[15872]62 push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
63 push(@{$hashArgOptLists->{"OptList"}},$options);
[2230]64
[21240]65
[15872]66 new ImageConverter($pluginlist, $inputargs, $hashArgOptLists);
67 my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
[1744]68
[1733]69 return bless $self, $class;
70}
71
[15872]72sub init {
73 my $self = shift (@_);
74 my ($verbosity, $outhandle, $failhandle) = @_;
75
76 $self->SUPER::init(@_);
77 $self->ImageConverter::init();
[17196]78 $self->{'cover_image'} = 0; # makes no sense for images
[15872]79}
80
[16847]81sub begin {
82 my $self = shift (@_);
83 my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
84
[16849]85 $self->SUPER::begin(@_);
[17250]86 $self->ImageConverter::begin(@_);
[16847]87}
88
[21287]89
[1733]90sub get_default_process_exp {
91 my $self = shift (@_);
92
[17666]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)$^;
[1733]95}
96
[9067]97# this makes no sense for images
98sub block_cover_image
99{
100 my $self =shift (@_);
101 my ($filename) = @_;
[2230]102
[9067]103 return;
104}
[2230]105
[15872]106# do plugin specific processing of doc_obj
107sub process {
[1733]108 my $self = shift (@_);
[15872]109 # options??
110 my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
111
[16820]112
[2230]113 my $outhandle = $self->{'outhandle'};
[16383]114 my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
[16820]115
[19361]116 if ($self->{'image_conversion_available'} == 1)
117 {
[16768]118 my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
[18320]119 my $url_encoded_filename = &util::rename_file($utf8_filename_no_path, $self->{'file_rename_method'});
[16768]120 $self->generate_images($filename_full_path, $url_encoded_filename, $doc_obj, $doc_obj->get_top_section()); # should we check the return value?
[19361]121 }
122 else
123 {
[16856]124 if ($gli) {
125 &gsprintf(STDERR, "<Warning p='ImagePlugin' r='{ImageConverter.noconversionavailable}: {ImageConverter.".$self->{'no_image_conversion_reason'}."}'>");
126 }
[17483]127 # all we do is add the original image as an associated file, and set up srclink etc
128 my $assoc_file = $doc_obj->get_assocfile_from_sourcefile();
129 my $section = $doc_obj->get_top_section();
130
131 $doc_obj->associate_file($filename_full_path, $assoc_file, "", $section);
132
[21760]133 #$doc_obj->add_metadata ($section, "srclink", "<a href=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">");
134 #$doc_obj->add_metadata ($section, "/srclink", "</a>");
135 $doc_obj->add_metadata ($section, "srclink_file", "[SourceFile]");
[19361]136 # We don't know the size of the image, but the browser should display it at full size
137 $doc_obj->add_metadata ($section, "srcicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\">");
[17483]138
[19361]139 # Add a fake thumbnail icon with the full-sized image scaled down by the browser
140 $doc_obj->add_metadata ($section, "thumbicon", "<img src=\"_httpprefix_/collect/[collection]/index/assoc/[assocfilepath]/[SourceFile]\" width=\"" . $self->{'thumbnailsize'} . "\">");
[2230]141 }
[15872]142 #we have no text - adds dummy text and NoText metadata
143 $self->add_dummy_text($doc_obj, $doc_obj->get_top_section());
[2230]144
[15872]145 return 1;
[4724]146
[3137]147}
[2230]148
[21240]149
[15872]150sub clean_up_after_doc_obj_processing {
[14951]151 my $self = shift(@_);
[1733]152
[15872]153 $self->ImageConverter::clean_up_temporary_files();
[1733]154}
155
1561;
[4724]157
158
159
160
161
162
163
164
165
166
167
Note: See TracBrowser for help on using the repository browser.