[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] | 26 | package ImagePlugin;
|
---|
[1733] | 27 |
|
---|
[15872] | 28 | use BasePlugin;
|
---|
| 29 | use ImageConverter;
|
---|
[1733] | 30 |
|
---|
[10254] | 31 | use strict;
|
---|
| 32 | no strict 'refs'; # allow filehandles to be variables and viceversa
|
---|
| 33 |
|
---|
[1733] | 34 | sub BEGIN {
|
---|
[15872] | 35 | @ImagePlugin::ISA = ('BasePlugin', 'ImageConverter');
|
---|
[1733] | 36 | }
|
---|
| 37 |
|
---|
[4744] | 38 | my $arguments =
|
---|
| 39 | [ { 'name' => "process_exp",
|
---|
[15872] | 40 | 'desc' => "{BasePlugin.process_exp}",
|
---|
[6408] | 41 | 'type' => "regexp",
|
---|
[4744] | 42 | 'deft' => &get_default_process_exp(),
|
---|
| 43 | 'reqd' => "no" },
|
---|
[15872] | 44 | ];
|
---|
[1758] | 45 |
|
---|
[15872] | 46 | my $options = { 'name' => "ImagePlugin",
|
---|
| 47 | 'desc' => "{ImagePlugin.desc}",
|
---|
[6408] | 48 | 'abstract' => "no",
|
---|
[3540] | 49 | 'inherits' => "yes",
|
---|
| 50 | 'args' => $arguments };
|
---|
| 51 |
|
---|
| 52 |
|
---|
[1744] | 53 |
|
---|
[1733] | 54 | sub new {
|
---|
[10218] | 55 | my ($class) = shift (@_);
|
---|
| 56 | my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
|
---|
| 57 | push(@$pluginlist, $class);
|
---|
[4724] | 58 |
|
---|
[15872] | 59 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
| 60 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
[2230] | 61 |
|
---|
[15872] | 62 | new ImageConverter($pluginlist, $inputargs, $hashArgOptLists);
|
---|
| 63 | my $self = new BasePlugin($pluginlist, $inputargs, $hashArgOptLists);
|
---|
[1744] | 64 |
|
---|
[1733] | 65 | return bless $self, $class;
|
---|
| 66 | }
|
---|
| 67 |
|
---|
[15872] | 68 | sub init {
|
---|
| 69 | my $self = shift (@_);
|
---|
| 70 | my ($verbosity, $outhandle, $failhandle) = @_;
|
---|
| 71 |
|
---|
| 72 | $self->SUPER::init(@_);
|
---|
| 73 | $self->ImageConverter::init();
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[16847] | 76 | sub begin {
|
---|
| 77 | my $self = shift (@_);
|
---|
| 78 | my ($pluginfo, $base_dir, $processor, $maxdocs) = @_;
|
---|
| 79 |
|
---|
[16849] | 80 | $self->SUPER::begin(@_);
|
---|
[16847] | 81 | $self->ImageConverter::begin();
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[1733] | 84 | sub get_default_process_exp {
|
---|
| 85 | my $self = shift (@_);
|
---|
| 86 |
|
---|
[1758] | 87 | return q^(?i)(\.jpe?g|\.gif|\.png|\.bmp|\.xbm|\.tif?f)$^;
|
---|
[1733] | 88 | }
|
---|
| 89 |
|
---|
[9067] | 90 | # this makes no sense for images
|
---|
| 91 | sub block_cover_image
|
---|
| 92 | {
|
---|
| 93 | my $self =shift (@_);
|
---|
| 94 | my ($filename) = @_;
|
---|
[2230] | 95 |
|
---|
[9067] | 96 | return;
|
---|
| 97 | }
|
---|
[2230] | 98 |
|
---|
[15872] | 99 | # do plugin specific processing of doc_obj
|
---|
| 100 | sub process {
|
---|
[1733] | 101 | my $self = shift (@_);
|
---|
[15872] | 102 | # options??
|
---|
| 103 | my ($pluginfo, $base_dir, $file, $metadata, $doc_obj, $gli) = @_;
|
---|
| 104 |
|
---|
[16820] | 105 |
|
---|
[2230] | 106 | my $outhandle = $self->{'outhandle'};
|
---|
[16383] | 107 | my ($filename_full_path, $filename_no_path) = &util::get_full_filenames($base_dir, $file);
|
---|
[16820] | 108 |
|
---|
[16010] | 109 | if ($self->{'image_conversion_available'} == 1) {
|
---|
[16768] | 110 | my $utf8_filename_no_path = $self->filepath_to_utf8($filename_no_path);
|
---|
| 111 | my $url_encoded_filename = &unicode::url_encode($utf8_filename_no_path);
|
---|
| 112 | $self->generate_images($filename_full_path, $url_encoded_filename, $doc_obj, $doc_obj->get_top_section()); # should we check the return value?
|
---|
[15872] | 113 | } else {
|
---|
| 114 | # do some basic stuff
|
---|
| 115 | # associate the image, fileformat, mimetype, srclink, srcicon
|
---|
| 116 | # do this if image magick not installed. but also if generate hasn't worked?? what about images too small?
|
---|
[2230] | 117 | }
|
---|
[15872] | 118 | #we have no text - adds dummy text and NoText metadata
|
---|
| 119 | $self->add_dummy_text($doc_obj, $doc_obj->get_top_section());
|
---|
[2230] | 120 |
|
---|
[15872] | 121 | return 1;
|
---|
[4724] | 122 |
|
---|
[3137] | 123 | }
|
---|
[2230] | 124 |
|
---|
[15872] | 125 | sub clean_up_after_doc_obj_processing {
|
---|
[14951] | 126 | my $self = shift(@_);
|
---|
[1733] | 127 |
|
---|
[15872] | 128 | $self->ImageConverter::clean_up_temporary_files();
|
---|
[1733] | 129 | }
|
---|
| 130 |
|
---|
| 131 | 1;
|
---|
[4724] | 132 |
|
---|
| 133 |
|
---|
| 134 |
|
---|
| 135 |
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 |
|
---|
| 140 |
|
---|
| 141 |
|
---|
| 142 |
|
---|