root/main/trunk/greenstone2/perllib/plugins/PharosImageIndexer.pm @ 21220

Revision 21220, 3.6 KB (checked in by kjdon, 10 years ago)

initial go at Pharos image indexing plugin

Line 
1###########################################################################
2#
3# PharosImageIndexer - helper plugin that does image conversion using ImageMagick
4#
5# A component of the Greenstone digital library software
6# from the New Zealand Digital Library Project at the
7# University of Waikato, New Zealand.
8#
9# Copyright (C) 2008 New Zealand Digital Library Project
10#
11# This program is free software; you can redistribute it and/or modify
12# it under the terms of the GNU General Public License as published by
13# the Free Software Foundation; either version 2 of the License, or
14# (at your option) any later version.
15#
16# This program is distributed in the hope that it will be useful,
17# but WITHOUT ANY WARRANTY; without even the implied warranty of
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19# GNU General Public License for more details.
20#
21# You should have received a copy of the GNU General Public License
22# along with this program; if not, write to the Free Software
23# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24#
25###########################################################################
26package PharosImageIndexer;
27
28use PrintInfo;
29
30
31use strict;
32no strict 'refs'; # allow filehandles to be variables and viceversa
33
34use gsprintf 'gsprintf';
35
36BEGIN {
37    @PharosImageIndexer::ISA = ('PrintInfo');
38}
39
40my $arguments = [
41         { 'name' => "enable_pharos_imageis",
42           'desc' => "{PharosImageIndexer.enable_pharos_imageis}",
43           'type' => "flag",
44           'reqd' => "no" },
45         ];
46
47my $options = { 'name' => "PharosImageIndexer",
48        'desc' => "{PharosImageIndexer.desc}",
49        'abstract' => "yes",
50        'inherits' => "yes",
51        'args' => $arguments };
52
53sub new {
54    my ($class) = shift (@_);
55    my ($pluginlist,$inputargs,$hashArgOptLists) = @_;
56    push(@$pluginlist, $class);
57
58    push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
59    push(@{$hashArgOptLists->{"OptList"}},$options);
60
61    my $self = new PrintInfo($pluginlist, $inputargs, $hashArgOptLists, 1);
62
63
64    return bless $self, $class;
65
66}
67
68# needs to be called after BasePlugin init, so that outhandle is set up.
69sub init {
70    my $self = shift(@_);
71
72    if ($self->{'enable_pharos_imageis'}) {
73    # Check that Pharos is installed and available on the path
74    my $pharos_available = 1;
75    ## change for windows!
76    #my $result = `phraros-imageis-identify 2>&1`;
77    #my $return_value = $?;
78    #if ( ($ENV{'GSDLOS'} eq "windows" && $return_value == 256) || $return_value == -1) {  # Linux and Windows return different values for "program not found"
79    #    $pharos_available = 0;
80    #}
81   
82    $self->{'pharos_available'} = 1; #$pharos_available;
83   
84    if ($self->{'pharos_available'} == 0) {
85        my $outhandle = $self->{'outhandle'};
86        &gsprintf($outhandle, "PharosImageIndexer: Pharos not installed\n");
87    }
88    }
89}
90   
91sub begin {
92
93}
94
95sub pharos_index_image {
96    my $self = shift(@_);
97
98    return unless $self->{'enable_pharos_imageis'};
99    # pass in the jpg thumbnail, and the doc obj
100    my ($filename_full_path, $doc_obj) = @_;
101    print STDERR "pharos indexing $filename_full_path\n";
102
103    my $collection = &util::get_current_collection_name();
104    my $id = $doc_obj->get_OID();
105
106    #my $result = `pharos-imageis-add.pl $collection $filename_full_path $id 2>&1`;
107    my $result = `imageis-add-jpg-file.sh $collection $filename_full_path 2>&1`;
108    my $return_value = $?;
109    if ($return_value != 0) {
110    my $outhandle = $self->{'outhandle'};
111    print $outhandle "Pharos Indexing failed for $filename_full_path, $id\n";
112    print $outhandle "$result\n";
113    }
114}
115
116
1171; 
Note: See TracBrowser for help on using the browser.