2 $lang_error=$lang[$lang_id][32];
5 function scan_error(&$scan_output, &$error_input, $lang_error) {
6 $scan_output="!!!!!!!! ".$lang_error." !!!!!!!!";
10 ////////////////////////////////////////////////////////////////////////
12 // build the scan command options
16 if($pos_x <= $MAX_SCAN_WIDTH_MM) {
17 $cmd_geometry_l=" -l ".$pos_x."mm";
20 $cmd_geometry_l=" -l ".$MAX_SCAN_WIDTH_MM."mm";
24 $lang[$lang_id][1]="<span class=\"input_error\">".$lang[$lang_id][1]."</span>";
25 scan_error($scan_output, $error_input, $lang_error);
30 if ($pos_y <= $MAX_SCAN_HEIGHT_MM) {
31 $cmd_geometry_t=" -t ".$pos_y."mm";
34 $cmd_geometry_t=" -t ".$MAX_SCAN_HEIGHT_MM."mm";
38 $lang[$lang_id][2]="<span class=\"input_error\">".$lang[$lang_id][2]."</span>";
39 scan_error($scan_output, $error_input, $lang_error);
44 if (($width >= 0) && $width <= $PREVIEW_WIDTH_MM) {
45 if($width <= $MAX_SCAN_WIDTH_MM) {
46 $cmd_geometry_x=" -x ".$width."mm";
49 $cmd_geometry_x=" -x ".$MAX_SCAN_WIDTH_MM."mm";
53 $lang[$lang_id][3]="<span class=\"input_error\">".$lang[$lang_id][3]."</span>";
54 scan_error($scan_output, $error_input, $lang_error);
58 $height = $geometry_y;
59 if (($height >= 0) && $height <=$PREVIEW_HEIGHT_MM) {
60 if($height <= $MAX_SCAN_HEIGHT_MM) {
61 $cmd_geometry_y=" -y ".$height."mm";
64 $cmd_geometry_y=" -y ".$MAX_SCAN_HEIGHT_MM."mm";
68 $lang[$lang_id][4]="<span class=\"input_error\">".$lang[$lang_id][4]."</span>";
69 scan_error($scan_output, $error_input, $lang_error);
72 $cmd_mode=" --mode \"".$mode."\"";
75 if (($resolution >= $resolution_min) && ($resolution <= $resolution_max)) {
76 $cmd_resolution=" --resolution ".$resolution."dpi";
78 $lang[$lang_id][18]="<span class=\"input_error\">".$lang[$lang_id][18]."</span>";
79 scan_error($scan_output, $error_input, $lang_error);
83 if ($do_brightness && (strtolower($mode) != 'lineart')) {
84 if (($brightness >= $contrast_minimum) && ($brightness <= $contrast_maximum)) {
85 $cmd_brightness=" --brightness ".$brightness;
87 $lang[$lang_id][22]="<span class=\"input_error\">".$lang[$lang_id][22]."</span>";
88 scan_error($scan_output, $error_input, $lang_error);
94 if (($contrast >= $contrast_minimum) && ($contrast <= $contrast_maximum)) {
95 $cmd_contrast=" --contrast ".$contrast;
97 $lang[$lang_id][23]="<span class=\"input_error\">".$lang[$lang_id][23]."</span>";
98 scan_error($scan_output, $error_input, $lang_error);
102 $cmd_usr_opt=" " . $usr_opt;
104 ////////////////////////////////////////////////////////////////////////
105 // build the device command
110 $file_save_image = 0;
111 $cmd_scan=$SCANIMAGE." -d ".$scanner.$cmd_geometry_l.$cmd_geometry_t.$cmd_geometry_x.$cmd_geometry_y.$cmd_mode.$cmd_resolution.$cmd_brightness.$cmd_contrast.$cmd_usr_opt;
113 if ($error_input == 0)
115 if ($action_preview) {
116 $preview_images = $temp_dir."preview_".$sid.".jpg";
117 $cmd_device = $SCANIMAGE." -d ".$scanner." --resolution ".$PREVIEW_DPI."dpi -l 0mm -t 0mm -x ".$MAX_SCAN_WIDTH_MM."mm -y ".$MAX_SCAN_HEIGHT_MM."mm".$cmd_mode.$cmd_brightness.$cmd_contrast.$cmd_usr_opt." | ".$PNMTOJPEG." --quality=50 > ".$preview_images;
119 else if ($action_save) {
120 $file_save = $save_dir.$_POST['file_name'].".".$format;
121 if (file_exists($file_save)) {
122 $file_save=$save_dir.$_POST['file_name']." ".date("Y-m-d H.i.s",time()).".".$format;
124 $file_save_image = 1;
126 if ($format == "jpg") {
127 $cmd_device = $cmd_scan." | {$PNMTOJPEG} --quality=100 > \"".$file_save."\"";
129 if ($format == "pnm") {
130 $cmd_device = $cmd_scan." > \"".$file_save."\"";
132 if ($format == "tif") {
133 $cmd_device = $cmd_scan." | {$PNMTOTIFF} > \"".$file_save."\"";
135 if ($format == "bmp") {
136 $cmd_device = $cmd_scan." | {$PNMTOBMP} > \"".$file_save."\"";
138 if ($format == "png") {
139 $cmd_device = $cmd_scan." | {$PNMTOPNG} > \"".$file_save."\"";
141 if ($format == "pdf") {
142 //$cmd_device = $cmd_scan." | {$CONVERT} pnm:- -compress jpeg -quality 100 -density {$resolution} pdf:- > \"".$file_save."\"";
145 convert: unable to read image data `-' @ error/pnm.c/ReadPNMImage/766.
146 convert: no images defined `pdf:-' @ error/convert.c/ConvertImageCommand/3044.
148 $cmd_device = $cmd_scan." | {$CONVERT} - -compress jpeg -quality 100 -density {$resolution} pdf:- > \"".$file_save."\"";
150 if ($format == "txt") {
151 $cmd_device = $cmd_scan." | ".$GOCR." - > \"".$file_save."\"";
156 if ($action_deletefiles && $do_file_delete) {
157 if(isset($_POST['selected_files'])) {
158 foreach($_POST['selected_files'] as $selected_file) {
159 $file_path = $save_dir . $selected_file;
160 if(is_readable($file_path)) {
167 ////////////////////////////////////////////////////////////////////////
168 // perform actions required
169 if ($cmd_device !== '') {
170 $scan_yes=`
$cmd_device`
;
172 $cmd_device = $lang[$lang_id][39];
176 if ($action_save && $append_file !== '') {
177 $escaped_file_save = str_replace(" ", "\\ ", $file_save);
178 $escaped_append_file = str_replace(" ", "\\ ", $append_file);
180 if ($format == "pdf" && $do_append_pdf) {
182 exec("$PDFUNITE $escaped_append_file $escaped_file_save {$escaped_append_file}_new");
183 exec("rm -f $escaped_append_file $escaped_file_save");
184 exec("mv {$escaped_append_file}_new $escaped_append_file");
186 else if ($format == "txt" && $do_append_txt) {
188 exec("cat $escaped_file_save >> $escaped_append_file");
189 exec("rm -f $escaped_file_save");
191 $file_save = $append_file;
194 if (($file_save !== '')&&($save_type=='popup')) {
195 echo "<script language=\"JavaScript\" type=\"text/javascript\">\n";
196 echo "window.open(\"./save.php?file_save=".$file_save."&file_save_image=".$file_save_image."&lang_id=".$lang_id."\",\"_blank\", \"width=400,height=500,left=320,top=200,scrollbars=yes,location=no,status=no,menubar=no\");\n";
200 //remove files from temp directory older then one day
201 if ($action_clean_tmp) {
202 $files = glob($temp_dir."*");
203 foreach($files as $file) {
204 if(is_file($file) && time() - filemtime($file) >= 24*60*60) {
210 if ($action_clean_output) {
211 $cmd_clean='rm -f '.$save_dir.'*';