PageRenderTime 51ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/www-apps/phpSANE/dev/incl/scan.php

https://repo.or.cz/anomen-overlay.git
PHP | 214 lines | 175 code | 23 blank | 16 comment | 71 complexity | bf0fd9a7d629ba803abe08055e5ed4f5 MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. $lang_error=$lang[$lang_id][32];
  3. $error_input=0;
  4. function scan_error(&$scan_output, &$error_input, $lang_error) {
  5. $scan_output="!!!!!!!! ".$lang_error." !!!!!!!!";
  6. $error_input=1;
  7. }
  8. ////////////////////////////////////////////////////////////////////////
  9. // build the scan command options
  10. $cmd_geometry_l="";
  11. if ($pos_x >= 0) {
  12. if($pos_x <= $MAX_SCAN_WIDTH_MM) {
  13. $cmd_geometry_l=" -l ".$pos_x."mm";
  14. }
  15. else {
  16. $cmd_geometry_l=" -l ".$MAX_SCAN_WIDTH_MM."mm";
  17. }
  18. }
  19. else {
  20. $lang[$lang_id][1]="<span class=\"input_error\">".$lang[$lang_id][1]."</span>";
  21. scan_error($scan_output, $error_input, $lang_error);
  22. }
  23. $cmd_geometry_t="";
  24. if ($pos_y >= 0) {
  25. if ($pos_y <= $MAX_SCAN_HEIGHT_MM) {
  26. $cmd_geometry_t=" -t ".$pos_y."mm";
  27. }
  28. else {
  29. $cmd_geometry_t=" -t ".$MAX_SCAN_HEIGHT_MM."mm";
  30. }
  31. }
  32. else {
  33. $lang[$lang_id][2]="<span class=\"input_error\">".$lang[$lang_id][2]."</span>";
  34. scan_error($scan_output, $error_input, $lang_error);
  35. }
  36. $cmd_geometry_x="";
  37. $width = $geometry_x;
  38. if (($width >= 0) && $width <= $PREVIEW_WIDTH_MM) {
  39. if($width <= $MAX_SCAN_WIDTH_MM) {
  40. $cmd_geometry_x=" -x ".$width."mm";
  41. }
  42. else {
  43. $cmd_geometry_x=" -x ".$MAX_SCAN_WIDTH_MM."mm";
  44. }
  45. }
  46. else {
  47. $lang[$lang_id][3]="<span class=\"input_error\">".$lang[$lang_id][3]."</span>";
  48. scan_error($scan_output, $error_input, $lang_error);
  49. }
  50. $cmd_geometry_y="";
  51. $height = $geometry_y;
  52. if (($height >= 0) && $height <=$PREVIEW_HEIGHT_MM) {
  53. if($height <= $MAX_SCAN_HEIGHT_MM) {
  54. $cmd_geometry_y=" -y ".$height."mm";
  55. }
  56. else {
  57. $cmd_geometry_y=" -y ".$MAX_SCAN_HEIGHT_MM."mm";
  58. }
  59. }
  60. else {
  61. $lang[$lang_id][4]="<span class=\"input_error\">".$lang[$lang_id][4]."</span>";
  62. scan_error($scan_output, $error_input, $lang_error);
  63. }
  64. $cmd_mode=" --mode \"".$mode."\"";
  65. $cmd_resolution="";
  66. if (($resolution >= $resolution_min) && ($resolution <= $resolution_max)) {
  67. $cmd_resolution=" --resolution ".$resolution."dpi";
  68. } else {
  69. $lang[$lang_id][18]="<span class=\"input_error\">".$lang[$lang_id][18]."</span>";
  70. scan_error($scan_output, $error_input, $lang_error);
  71. }
  72. $cmd_brightness="";
  73. if ($do_brightness && (strtolower($mode) != 'lineart')) {
  74. if (($brightness >= $contrast_minimum) && ($brightness <= $contrast_maximum)) {
  75. $cmd_brightness=" --brightness ".$brightness;
  76. } else {
  77. $lang[$lang_id][22]="<span class=\"input_error\">".$lang[$lang_id][22]."</span>";
  78. scan_error($scan_output, $error_input, $lang_error);
  79. }
  80. }
  81. $cmd_contrast="";
  82. if ($do_contrast) {
  83. if (($contrast >= $contrast_minimum) && ($contrast <= $contrast_maximum)) {
  84. $cmd_contrast=" --contrast ".$contrast;
  85. } else {
  86. $lang[$lang_id][23]="<span class=\"input_error\">".$lang[$lang_id][23]."</span>";
  87. scan_error($scan_output, $error_input, $lang_error);
  88. }
  89. }
  90. $cmd_usr_opt=" " . $usr_opt;
  91. ////////////////////////////////////////////////////////////////////////
  92. // build the device command
  93. $scan_yes='';
  94. $cmd_device = '';
  95. $file_save = '';
  96. $file_save_image = 0;
  97. $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;
  98. if ($error_input == 0)
  99. {
  100. if ($action_preview) {
  101. $preview_images = $temp_dir."preview_".$sid.".jpg";
  102. $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;
  103. }
  104. else if ($action_save) {
  105. $file_save = $save_dir.$_POST['file_name'].".".$format;
  106. if (file_exists($file_save)) {
  107. $file_save=$save_dir.$_POST['file_name']." ".date("Y-m-d H.i.s",time()).".".$format;
  108. }
  109. $file_save_image = 1;
  110. if ($format == "jpg") {
  111. $cmd_device = $cmd_scan." | {$PNMTOJPEG} --quality=100 > \"".$file_save."\"";
  112. }
  113. if ($format == "pnm") {
  114. $cmd_device = $cmd_scan." > \"".$file_save."\"";
  115. }
  116. if ($format == "tif") {
  117. $cmd_device = $cmd_scan." | {$PNMTOTIFF} > \"".$file_save."\"";
  118. }
  119. if ($format == "bmp") {
  120. $cmd_device = $cmd_scan." | {$PNMTOBMP} > \"".$file_save."\"";
  121. }
  122. if ($format == "png") {
  123. $cmd_device = $cmd_scan." | {$PNMTOPNG} > \"".$file_save."\"";
  124. }
  125. if ($format == "pdf") {
  126. //$cmd_device = $cmd_scan." | {$CONVERT} pnm:- -compress jpeg -quality 100 -density {$resolution} pdf:- > \"".$file_save."\"";
  127. /*
  128. Bugfix:
  129. convert: unable to read image data `-' @ error/pnm.c/ReadPNMImage/766.
  130. convert: no images defined `pdf:-' @ error/convert.c/ConvertImageCommand/3044.
  131. */
  132. $cmd_device = $cmd_scan." | {$CONVERT} - -compress jpeg -quality 100 -density {$resolution} pdf:- > \"".$file_save."\"";
  133. }
  134. if ($format == "txt") {
  135. $cmd_device = $cmd_scan." | ".$GOCR." - > \"".$file_save."\"";
  136. }
  137. }
  138. }
  139. if ($action_deletefiles && $do_file_delete) {
  140. if(isset($_POST['selected_files'])) {
  141. foreach($_POST['selected_files'] as $selected_file) {
  142. $file_path = $save_dir . $selected_file;
  143. if(is_readable($file_path)) {
  144. unlink($file_path);
  145. }
  146. }
  147. }
  148. }
  149. ////////////////////////////////////////////////////////////////////////
  150. // perform actions required
  151. if ($cmd_device !== '') {
  152. $scan_yes=`$cmd_device`;
  153. } else {
  154. $cmd_device = $lang[$lang_id][39];
  155. }
  156. //merge files
  157. if ($action_save && $append_file !== '') {
  158. $escaped_file_save = str_replace(" ", "\\ ", $file_save);
  159. $escaped_append_file = str_replace(" ", "\\ ", $append_file);
  160. if ($format == "pdf" && $do_append_pdf) {
  161. //merge pdf files
  162. exec("$PDFUNITE $escaped_append_file $escaped_file_save {$escaped_append_file}_new");
  163. exec("rm -f $escaped_append_file $escaped_file_save");
  164. exec("mv {$escaped_append_file}_new $escaped_append_file");
  165. }
  166. else if ($format == "txt" && $do_append_txt) {
  167. //merge txt files
  168. exec("cat $escaped_file_save >> $escaped_append_file");
  169. exec("rm -f $escaped_file_save");
  170. }
  171. $file_save = $append_file;
  172. }
  173. if (($file_save !== '')&&($save_type=='popup')) {
  174. echo "<script language=\"JavaScript\" type=\"text/javascript\">\n";
  175. 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";
  176. echo "</script>\n";
  177. }
  178. //remove files from temp directory older then one day
  179. if ($action_clean_tmp) {
  180. $files = glob($temp_dir."*");
  181. foreach($files as $file) {
  182. if(is_file($file) && time() - filemtime($file) >= 24*60*60*$keep_save_files_days) {
  183. unlink($file);
  184. }
  185. }
  186. }
  187. if ($action_clean_output) {
  188. $cmd_clean='rm -f '.$save_dir.'*';
  189. exec($cmd_clean);
  190. }
  191. ?>