Home | News | Projects | Releases
Bugs | RFE | Repositories | Help
Forked Xestia Scanner Server!
[xestiascansrv/.git] / cgi-files / Modules / Output / JPEG.pm
1 #################################################################################
2 # Xestia Scanner Server Output Module - JPEG Output Module.                     #
3 # Outputs the image into the JPEG 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::JPEG;
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");
105         
106         $options{compression}{type} = "textbox";
107         $options{compression}{string} = languagestrings("compressionratio");
108         $options{compression}{maxlength} = "3";
109         $options{compression}{value} = "100";
110         $options{compression}{size} = "3";
111         
112         return %options;
116 sub errorflag{
117 #################################################################################
118 # errorflag: Returns an error flag (if any).                                    #
119 #                                                                               #
120 # Usage:                                                                        #
121 #                                                                               #
122 # $errorflag    = $outputmodule->errorflag();                                   #
123 #################################################################################
124         
125         return $error_flag;
129 sub errormessage{
130 #################################################################################
131 # errormessage: Returns an error message (if any).                              #
132 #                                                                               #
133 # Usage:                                                                        #
134 #                                                                               #
135 # $errormessage = $outputmodule->errormessage();                                #
136 #################################################################################
138         return $error_message;
142 sub clearflag{
143 #################################################################################
144 # clearflag: Clears the error message flag and the error message itself.        #
145 #                                                                               #
146 # Usage:                                                                        #
147 #                                                                               #
148 # $outputmodule->clearflag();                                                   #
149 #################################################################################
151         $error_flag     = 0;
152         $error_message  = "";
156 sub processimage{
157 #################################################################################
158 # processimage: Processes the image.                                            #
159 #                                                                               #
160 # Usage:                                                                        #
161 #                                                                               #
162 # $outputmodule->processimage(hexnumber, outputmoduleoptions);                  #
163 #                                                                               #
164 # hexnumber             Specifies the hex number for the image.                 #
165 # outputmoduleoptions   Specifies the options for the output module as a hash.  #
166 #################################################################################
167         
168         my ($outputmoduleoptions, %outputmoduleoptions);
169         
170         my $class = shift;
171         my $hexnumber = shift;
172         %outputmoduleoptions = @_;
173         
174         my $compression = $outputmoduleoptions{compression};
175         
176         my $im = new Image::Magick;
177         $im->Read("/tmp/xestiascanserver-preview-" . $hexnumber . ".pnm");
178         
179         $compression = 100 if $compression > 100;
180         $compression = 0 if $compression < 0;
181         
182         $im->Set(quality => $compression);
183         
184         $im->Write("/tmp/xestiascanserver-final-" . $hexnumber . ".jpg");
185         
186         return "/tmp/xestiascanserver-final-" . $hexnumber . ".jpg";
187         
190 sub languagestrings{
191 #################################################################################
192 # languagestrings: Language strings that are used in this module.               #
193 #                                                                               #
194 # Usage:                                                                        #
195 #                                                                               #
196 # $string = $outputmodule->languagestrings("langstring");                       #
197 #################################################################################
199         my $langstring = shift;
201         my $language_string;
202         my ($language_strings, %language_strings);
203         my $item;
204         
205         if ($language_name eq "en-GB"){
207                 # Language strings for English (British) language.
209                 $language_strings{compressionratio} = "Compression Ratio (%):";
211         } else {
213                 # Invalid language so use English (British) as default.
215                 $language_strings{compressionratio} = "Compression Ratio (%):";
217         }
219         $language_string = $language_strings{$langstring};
220         
221         foreach $item (@_){
223                 $language_string =~ s/%s/$item/;
225         }
227         return $language_string;
231 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