Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Forked Xestia Scanner Server!
[xestiascansrv/.git] / cgi-files / Modules / Output / PNG.pm
1 #################################################################################
2 # Xestia Scanner Server Output Module - PNG Output Module.                      #
3 # Outputs the image into the PNG format.                                        #
4 #                                                                               #
5 # Copyright (C) 2010-11 Steve Brokenshire <sbrokenshire@xestia.co.uk>           #
6 #                                                                               #
7 # This module is licensed under the same license as Xestia Scanner Server which #
8 # is licensed under the GPL version 3.                                          #
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, version 3 of the License.                       #
13 #                                                                               #
14 # This program is distributed in the hope that it will be useful,               #
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of                #
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 #
17 # GNU General Public License for more details.                                  #
18 #                                                                               #
19 # You should have received a copy of the GNU General Public License             #
20 # along with this program.  If not, see <http://www.gnu.org/licenses/>.         #
21 ################################################################################# 
23 # Define the package (perl module) name.
25 package Modules::Output::PNG;
27 # Enable strict and use warnings.
29 use strict;
30 use warnings;
31 use Encode qw(decode_utf8);
32 use Tie::IxHash;
33 use Modules::System::Common;
34 use Image::Magick;
36 # Set the following values.
38 our $VERSION = "0.1.0";
39 my ($pages, %pages);
40 my $error_flag = 0;
41 my $error_message = "";
42 my $language_name = "";
43 my %optionshash = ();
45 tie(%pages, "Tie::IxHash");
47 sub new{
48 #################################################################################
49 # new: Create an instance of Modules::Output::Normal                            #
50 #                                                                               #
51 # Usage:                                                                        #
52 #                                                                               #
53 # $dbmodule = Modules::Output::Normal->new();                                   #
54 #################################################################################
55         
56         # Get the perl module name.
58         my $class = shift;
59         my $self = {};
61         return bless($self, $class);
63 }
65 sub initialise{
66 #################################################################################
67 # initialise: Initialises the output module.                                    #
68 #                                                                               #
69 # Usage:                                                                        #
70 #                                                                               #
71 # $outputmodule->initialise();                                                  #
72 #################################################################################
74 }
76 sub loadsettings{
77 #################################################################################
78 # loadsettings: Loads some settings for the output module.                      #
79 #                                                                               #
80 # Usage:                                                                        #
81 #                                                                               #
82 # $outputmodule->loadsettings(language);                                        #
83 #                                                                               #
84 # language      Specifies the language to use.                                  #
85 #################################################################################
86         
87         my $class = shift;
88         my $passed_lang = shift;
89         
90         $language_name = $passed_lang;
91         
92 }
94 sub getoptions{
95 #################################################################################
96 # getoptions: Gets the options that will be used.                               #
97 #                                                                               #
98 # Usage:                                                                        #
99 #                                                                               #
100 # %options = $outputmodule->getoptions();                                       #
101 #################################################################################
103         my (%options, $options);
104         tie(%options, "Tie::IxHash");
106         #$options{seperatedirdatabase}{type} = "checkbox";
107         #$options{seperatedirdatabase}{string} = "Disable content type (make browser guess!)";
108         return %options;
112 sub errorflag{
113 #################################################################################
114 # errorflag: Returns an error flag (if any).                                    #
115 #                                                                               #
116 # Usage:                                                                        #
117 #                                                                               #
118 # $errorflag    = $outputmodule->errorflag();                                   #
119 #################################################################################
120         
121         return $error_flag;
125 sub errormessage{
126 #################################################################################
127 # errormessage: Returns an error message (if any).                              #
128 #                                                                               #
129 # Usage:                                                                        #
130 #                                                                               #
131 # $errormessage = $outputmodule->errormessage();                                #
132 #################################################################################
134         return $error_message;
138 sub clearflag{
139 #################################################################################
140 # clearflag: Clears the error message flag and the error message itself.        #
141 #                                                                               #
142 # Usage:                                                                        #
143 #                                                                               #
144 # $outputmodule->clearflag();                                                   #
145 #################################################################################
147         $error_flag     = 0;
148         $error_message  = "";
152 sub processimage{
153 #################################################################################
154 # processimage: Processes the image.                                            #
155 #                                                                               #
156 # Usage:                                                                        #
157 #                                                                               #
158 # $outputmodule->processimage(hexnumber, outputmoduleoptions);                  #
159 #                                                                               #
160 # hexnumber             Specifies the hex number for the image.                 #
161 # outputmoduleoptions   Specifies the options for the output module as a hash.  #
162 #################################################################################
163         
164         my $class = shift;
165         my $hexnumber = shift;
166         my $outputmoduleoptions = @_;
167         
168         my $errmsg;
169         
170         my $im = new Image::Magick;
171         $errmsg = $im->Read("/tmp/xestiascanserver-preview-" . $hexnumber . ".pnm");
172         
173         if ($errmsg){
174                 
175                 $error_flag = 1;
176                 $error_message = $errmsg;
177                 return;
178                 
179         }
180         
181         $errmsg = $im->Write("/tmp/xestiascanserver-final-" . $hexnumber . ".png");
183         if ($errmsg){
184                 
185                 $error_flag = 1;
186                 $error_message = $errmsg;
187                 return;
188                 
189         }
190         
191         return "/tmp/xestiascanserver-final-" . $hexnumber . ".png";
192         
195 sub languagestrings{
196 #################################################################################
197 # languagestrings: Language strings that are used in this module.               #
198 #                                                                               #
199 # Usage:                                                                        #
200 #                                                                               #
201 # $string = $outputmodule->languagestrings("langstring");                       #
202 #################################################################################
204         my $langstring = shift;
206         my $language_string;
207         my ($language_strings, %language_strings);
208         my $item;
210         if ($language_name eq "en-GB" or !$language_name){
212                 # Language strings for English (British) language.
214                 $language_strings{seperatedirdatabase} = "Seperate directory for each database.";
215                 $language_strings{invalidpermissionset} = "Invalid file permissions set.";
217         } else {
219                 # Invalid language so use English (British) as default.
221                 $language_strings{seperatedirdatabase} = "Seperate directory for each database.";
222                 $language_strings{invalidpermissionset} = "Invalid file permissions set.";
224         }
226         $language_string = $language_strings{$langstring};
227         
228         foreach $item (@_){
230                 $language_string =~ s/%s/$item/;
232         }
234         return $language_string;
238 1;
Xestia Software Development
Yn Maystri
© 2006 - 2019 Xestia Software Development
Software

Xestia Address Book
Xestia Calendar
Development

Xestia Gelforn
Everything else

About
News
Privacy Policy