www-apps/phpSANE-0.8.0
[anomen-overlay.git] / www-apps / phpSANE / dev / incl / scan.php
blob74ad9e45385bd09b056c1ae7a696c25a4bd44766
1 <?php
2 $lang_error=$lang[$lang_id][32];
3 $error_input=0;
5 function scan_error(&$scan_output, &$error_input, $lang_error) {
6 $scan_output="!!!!!!!! ".$lang_error." !!!!!!!!";
7 $error_input=1;
10 ////////////////////////////////////////////////////////////////////////
12 // build the scan command options
14 $cmd_geometry_l="";
15 if ($pos_x >= 0) {
16 if($pos_x <= $MAX_SCAN_WIDTH_MM) {
17 $cmd_geometry_l=" -l ".$pos_x."mm";
19 else {
20 $cmd_geometry_l=" -l ".$MAX_SCAN_WIDTH_MM."mm";
23 else {
24 $lang[$lang_id][1]="<span class=\"input_error\">".$lang[$lang_id][1]."</span>";
25 scan_error($scan_output, $error_input, $lang_error);
28 $cmd_geometry_t="";
29 if ($pos_y >= 0) {
30 if ($pos_y <= $MAX_SCAN_HEIGHT_MM) {
31 $cmd_geometry_t=" -t ".$pos_y."mm";
33 else {
34 $cmd_geometry_t=" -t ".$MAX_SCAN_HEIGHT_MM."mm";
37 else {
38 $lang[$lang_id][2]="<span class=\"input_error\">".$lang[$lang_id][2]."</span>";
39 scan_error($scan_output, $error_input, $lang_error);
42 $cmd_geometry_x="";
43 $width = $geometry_x;
44 if (($width >= 0) && $width <= $PREVIEW_WIDTH_MM) {
45 if($width <= $MAX_SCAN_WIDTH_MM) {
46 $cmd_geometry_x=" -x ".$width."mm";
48 else {
49 $cmd_geometry_x=" -x ".$MAX_SCAN_WIDTH_MM."mm";
52 else {
53 $lang[$lang_id][3]="<span class=\"input_error\">".$lang[$lang_id][3]."</span>";
54 scan_error($scan_output, $error_input, $lang_error);
57 $cmd_geometry_y="";
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";
63 else {
64 $cmd_geometry_y=" -y ".$MAX_SCAN_HEIGHT_MM."mm";
67 else {
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."\"";
74 $cmd_resolution="";
75 if (($resolution >= $resolution_min) && ($resolution <= $resolution_max)) {
76 $cmd_resolution=" --resolution ".$resolution."dpi";
77 } else {
78 $lang[$lang_id][18]="<span class=\"input_error\">".$lang[$lang_id][18]."</span>";
79 scan_error($scan_output, $error_input, $lang_error);
82 $cmd_brightness="";
83 if ($do_brightness && (strtolower($mode) != 'lineart')) {
84 if (($brightness >= $contrast_minimum) && ($brightness <= $contrast_maximum)) {
85 $cmd_brightness=" --brightness ".$brightness;
86 } else {
87 $lang[$lang_id][22]="<span class=\"input_error\">".$lang[$lang_id][22]."</span>";
88 scan_error($scan_output, $error_input, $lang_error);
92 $cmd_contrast="";
93 if ($do_contrast) {
94 if (($contrast >= $contrast_minimum) && ($contrast <= $contrast_maximum)) {
95 $cmd_contrast=" --contrast ".$contrast;
96 } else {
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
107 $scan_yes='';
108 $cmd_device = '';
109 $file_save = '';
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."\"";
144 Bugfix:
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)) {
161 unlink($file_path);
167 ////////////////////////////////////////////////////////////////////////
168 // perform actions required
169 if ($cmd_device !== '') {
170 $scan_yes=`$cmd_device`;
171 } else {
172 $cmd_device = $lang[$lang_id][39];
175 //merge files
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) {
181 //merge pdf files
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) {
187 //merge txt files
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";
197 echo "</script>\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) {
205 unlink($file);
210 if ($action_clean_output) {
211 $cmd_clean='rm -f '.$save_dir.'*';
212 exec($cmd_clean);