1 #################################################################################
2 # Xestia Scanner Server Output Module - JPEG Output Module. #
3 # Outputs the image into the JPEG format. #
5 # Copyright (C) 2010-11 Steve Brokenshire <sbrokenshire@xestia.co.uk> #
7 # This module is licensed under the same license as Xestia Scanner Server which #
8 # is licensed under the GPL version 3. #
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. #
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. #
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.
31 use Encode qw(decode_utf8);
33 use Modules::System::Common;
36 # Set the following values.
38 our $VERSION = "0.1.0";
41 my $error_message = "";
42 my $language_name = "";
45 tie(%pages, "Tie::IxHash");
48 #################################################################################
49 # new: Create an instance of Modules::Output::Normal #
53 # $dbmodule = Modules::Output::Normal->new(); #
54 #################################################################################
56 # Get the perl module name.
61 return bless($self, $class);
66 #################################################################################
67 # initialise: Initialises the output module. #
71 # $outputmodule->initialise(); #
72 #################################################################################
77 #################################################################################
78 # loadsettings: Loads some settings for the output module. #
82 # $outputmodule->loadsettings(language); #
84 # language Specifies the language to use. #
85 #################################################################################
88 my $passed_lang = shift;
90 $language_name = $passed_lang;
95 #################################################################################
96 # getoptions: Gets the options that will be used. #
100 # %options = $outputmodule->getoptions(); #
101 #################################################################################
103 my (%options, $options);
104 tie(%options, "Tie::IxHash");
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";
117 #################################################################################
118 # errorflag: Returns an error flag (if any). #
122 # $errorflag = $outputmodule->errorflag(); #
123 #################################################################################
130 #################################################################################
131 # errormessage: Returns an error message (if any). #
135 # $errormessage = $outputmodule->errormessage(); #
136 #################################################################################
138 return $error_message;
143 #################################################################################
144 # clearflag: Clears the error message flag and the error message itself. #
148 # $outputmodule->clearflag(); #
149 #################################################################################
157 #################################################################################
158 # processimage: Processes the image. #
162 # $outputmodule->processimage(hexnumber, outputmoduleoptions); #
164 # hexnumber Specifies the hex number for the image. #
165 # outputmoduleoptions Specifies the options for the output module as a hash. #
166 #################################################################################
168 my ($outputmoduleoptions, %outputmoduleoptions);
171 my $hexnumber = shift;
172 %outputmoduleoptions = @_;
174 my $compression = $outputmoduleoptions{compression};
176 my $im = new Image::Magick;
177 $im->Read("/tmp/xestiascanserver-preview-" . $hexnumber . ".pnm");
179 $compression = 100 if $compression > 100;
180 $compression = 0 if $compression < 0;
182 $im->Set(quality => $compression);
184 $im->Write("/tmp/xestiascanserver-final-" . $hexnumber . ".jpg");
186 return "/tmp/xestiascanserver-final-" . $hexnumber . ".jpg";
191 #################################################################################
192 # languagestrings: Language strings that are used in this module. #
196 # $string = $outputmodule->languagestrings("langstring"); #
197 #################################################################################
199 my $langstring = shift;
202 my ($language_strings, %language_strings);
205 if ($language_name eq "en-GB"){
207 # Language strings for English (British) language.
209 $language_strings{compressionratio} = "Compression Ratio (%):";
213 # Invalid language so use English (British) as default.
215 $language_strings{compressionratio} = "Compression Ratio (%):";
219 $language_string = $language_strings{$langstring};
223 $language_string =~ s/%s/$item/;
227 return $language_string;