Changeset 1011
- Timestamp:
- 05/21/05 09:53:27 (4 years ago)
- Files:
-
- trunk/lib/midcom/config/midcom_config.php (modified) (3 diffs)
- trunk/lib/midcom/helper/datamanager/datatype_image.php (modified) (17 diffs)
- trunk/lib/midcom/services/indexer/document_attachment.php (modified) (6 diffs)
- trunk/lib/net/siriux/photos/Photo.php (modified) (6 diffs)
- trunk/lib/net/siriux/photos/admin.php (modified) (8 diffs)
- trunk/lib/net/siriux/photos/filter.php (modified) (16 diffs)
- trunk/lib/net/siriux/photos/style/admin_upload.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/midcom/config/midcom_config.php
r1000 r1011 142 142 * that, it might contain an URL which is not suitable for relcoations. 143 143 * 144 * <b>Utility Programs</b> 145 * 146 * The various paths set here lead to the utility programs required by MidCOM, both 147 * mandatory and optional applications are listed here. To indicate that a certain 148 * application is unavailable, set it to null. It is recommended to set this in the 149 * /etc/midgard/midcom.conf file. The defaults assume that the files are within the 150 * $PATH of the Apache user and should be sufficient in most cases. Package mainatainers 151 * are encouraged to make the paths explicit. 152 * 153 * - <b>string utility_imagemagick_base:</b> The base path of the ImageMagick executables, 154 * the tools <i>mogrify</i>, <i>identify</i> and <i>convert</i> are needed for almost 155 * all kinds of image operations in MidCOM and have to be present therefore. The path 156 * entered here requires a trailing slash. 157 * - <b>string utility_jpegtran:</b> JPEGTran is used to do losless rotation of JPEG 158 * images for automatic EXIF rotation in n.s.photos for example. If unavailable, 159 * there is an automatic fallback to imagemagick. 160 * - <b>string utility_unzip:</b> The unzip utility, used for bulk uploads. 161 * - <b>string utility_gzip:</b> The gzip utility, used for bulk uploads. 162 * - <b>string utility_tar:</b> The tar utility, used for bulk uploads. 163 * - <b>string utility_jhead:</b> The jhead utility, used as a fallback to read EXIF 164 * information if the PHP implementation (pre 4.3) is buggy. 165 * - <b>string utility_find:</b> The Find utility is used for bulk upload preprocessing 166 * and the like. 167 * - <b>string utility_file:</b> Utility to identify all kinds of uploaded files. 168 * - <b>string utility_catdoc:</b> Transforms Word Documents into text for indexing. 169 * - <b>string utility_pdftotext:</b> Transforms PDF Documents into text for indexing. 170 * - <b>string utility_unrtf:</b> Transforms RTF Documents into text files for indexing. 171 * 172 * 144 173 * <b>Visibility settings (NAP)</b> 145 174 * … … 149 178 * - <b>bool show_unapproved_objects:</b> This flag indicates wether objects should be 150 179 * shown even if they are not approved. This defaults to true. 151 *152 180 * 153 181 * … … 218 246 $GLOBALS['midcom_config_default']['midcom_root_topic_guid'] = ''; 219 247 $GLOBALS['midcom_config_default']['midcom_site_url'] = '/'; 248 249 250 // Utilities 251 $GLOBALS['midcom_config_default']['utility_imagemagick_base'] = ''; 252 $GLOBALS['midcom_config_default']['utility_jpegtran'] = 'jpegtran'; 253 $GLOBALS['midcom_config_default']['utility_unzip'] = 'unzip'; 254 $GLOBALS['midcom_config_default']['utility_gzip'] = 'gzip'; 255 $GLOBALS['midcom_config_default']['utility_tar'] = 'tar'; 256 $GLOBALS['midcom_config_default']['utility_jhead'] = 'jhead'; 257 $GLOBALS['midcom_config_default']['utility_find'] = 'find'; 258 $GLOBALS['midcom_config_default']['utility_file'] = 'file'; 259 $GLOBALS['midcom_config_default']['utility_catdoc'] = 'catdoc'; 260 $GLOBALS['midcom_config_default']['utility_pdftotext'] = 'pdftotext'; 261 $GLOBALS['midcom_config_default']['utility_unrtf'] = 'unrtf'; 262 263 264 // gzip tar jhead 265 220 266 221 267 trunk/lib/midcom/helper/datamanager/datatype_image.php
r752 r1011 133 133 } 134 134 135 function _handle_upload ($params, $meta) { 135 function _handle_upload ($params, $meta) 136 { 136 137 debug_push("midcom_helper_datamanager_datatype_image::_handle_upload"); 137 138 … … 152 153 $convert_options_thumb = '+profile "*" -quality ' . (int) $this->_thumbjpegqual; 153 154 154 /* check if "convert" is installed */155 $convert = exec("which convert");156 if ($convert == "") {157 $midcom_errstr = "Could not find image convert utility in path.";158 debug_add($midcom_errstr, MIDCOM_LOG_ERROR);159 debug_add("Leaving");160 debug_pop();161 return false;162 }163 164 155 $id = parent::_handle_upload($params, $meta); 165 156 if (!$id) { … … 179 170 /* store image as-is, no thumbnail etc. */ 180 171 181 if ($thumbtype == "asis") { 172 if ($thumbtype == "asis") 173 { 182 174 debug_add("Storing thumbnail as-is, no further conversion.", MIDCOM_LOG_DEBUG); 183 175 /* thumbguid == attachment guid … … 192 184 /* get mimetype and mimetype to convert to */ 193 185 $file_orig = $params["tmp_name"]; 194 $orig_mimetype = exec(" file -ib $file_orig2>/dev/null");195 debug_add("original mimetype: $orig_mimetype", MIDCOM_LOG_DEBUG);186 $orig_mimetype = exec("{$GLOBALS['midcom_config']['utility_file']} -ib {$file_orig} 2>/dev/null"); 187 debug_add("original mimetype: {$orig_mimetype}", MIDCOM_LOG_DEBUG); 196 188 197 189 /* auto detect mime type and file extension */ 198 switch ($orig_mimetype) { 190 switch ($orig_mimetype) 191 { 199 192 case "image/png": 200 193 case "image/gif": … … 213 206 debug_add("auto detected extension: " . $auto_ext, MIDCOM_LOG_DEBUG); 214 207 215 switch ($storetype) { 208 switch ($storetype) 209 { 216 210 case "": 217 211 // auto detect … … 240 234 debug_add("new extension: " . $new_ext, MIDCOM_LOG_DEBUG); 241 235 242 switch ($thumbtype) { 236 switch ($thumbtype) 237 { 243 238 case "": 244 239 // auto detect … … 269 264 $file_tmp_thumb = $tmp_dir."/thumb_".$file_base.".".$thumb_ext; 270 265 271 if (($new_mimetype != $orig_mimetype) and ($storetype != "asis")) { 266 if ( $new_mimetype != $orig_mimetype 267 && $storetype != "asis") 268 { 272 269 // convert original and overwrite attachment 273 270 debug_add("convert original and overwrite attachment...", MIDCOM_LOG_DEBUG); 274 271 275 272 // the "[0]" in the command line makes convert take only the first frame of an animated gif file... 276 $cmd = " convert $convert_options ". escapeshellarg($file_orig."[0]") . " ".escapeshellarg($file_tmp_orig);273 $cmd = "{$GLOBALS['midcom_config']['utility_imagemagick_base']}convert $convert_options ". escapeshellarg($file_orig."[0]") . " ".escapeshellarg($file_tmp_orig); 277 274 debug_add("Executing: $cmd", MIDCOM_LOG_DEBUG); 278 275 exec($cmd); 279 276 280 277 $dest = mgd_open_attachment($id); 281 if (!$dest) { 278 if (!$dest) 279 { 282 280 $midcom_errstr = "Could not open File Attachment for writing: " . mgd_errstr(); 283 281 debug_add($midcom_errstr, MIDCOM_LOG_ERROR); … … 286 284 } 287 285 $source = fopen($file_tmp_orig,"r"); 288 if (!$source) { 286 if (!$source) 287 { 289 288 $midcom_errstr = "Could not open converted image for reading, aborting thumbnail creation."; 290 289 debug_add($midcom_errstr, MIDCOM_LOG_ERROR); … … 294 293 return false; 295 294 } 296 while (! feof($source)) 295 while (! feof($source)) 296 { 297 297 fwrite($dest, fread($source, 100000)); 298 } 298 299 299 300 fclose($dest); … … 310 311 311 312 $size = getimagesize($file_orig); 312 if ($size) { 313 if ($size) 314 { 313 315 $orig_x = $size[0]; 314 316 $orig_y = $size[1]; 315 317 debug_add("original size: ".$orig_x."x".$orig_y, MIDCOM_LOG_DEBUG); 316 } else { 318 } 319 else 320 { 317 321 $orig_x = false; 318 322 $orig_y = false; … … 321 325 322 326 /* create thumbnail */ 323 $cmd = " convert $convert_options_thumb -geometry '".$this->_thumbwidth."x".$this->_thumbheight.">' ". escapeshellarg($file_orig."[0]")." ".escapeshellarg($file_tmp_thumb);327 $cmd = "{$GLOBALS['midcom_config']['utility_imagemagick_base']}convert $convert_options_thumb -geometry '".$this->_thumbwidth."x".$this->_thumbheight.">' ". escapeshellarg($file_orig."[0]")." ".escapeshellarg($file_tmp_thumb); 324 328 debug_add("Executing: $cmd", MIDCOM_LOG_DEBUG); 325 329 exec($cmd); 326 330 327 /* run external filters328 *329 * Code disabled until the author takes a minute to think about uniform code formatting,330 * things like indentation width and spaces between operators331 *332 if ($this->_filterfunction) {333 $filter = $this->_filterfunction;334 debug_add("Executing: ".$filter."(".$file_tmp_thumb.")", MIDCOM_LOG_DEBUG);335 $filter($file_tmp_thumb);336 }337 */338 339 331 $size = getimagesize($file_tmp_thumb); 340 if ($size) { 332 if ($size) 333 { 341 334 $new_x = $size[0]; 342 335 $new_y = $size[1]; 343 336 debug_add("thumbnail size: ".$new_x."x".$new_y, MIDCOM_LOG_DEBUG); 344 } else { 337 } 338 else 339 { 345 340 $new_x = false; 346 341 $new_y = false; … … 352 347 $filename = basename($file_tmp_thumb); 353 348 354 if ($this->_storage->getattachment($filename)) { 349 if ($this->_storage->getattachment($filename)) 350 { 355 351 $midcom_errstr = "A file with the thumbnail file name already exists."; 356 352 debug_add($midcom_errstr, MIDCOM_LOG_ERROR); … … 360 356 361 357 $thumb_id = $this->_storage->createattachment($filename, $att->title, $new_mimetype); 362 if (!$thumb_id) { 358 if (!$thumb_id) 359 { 363 360 $midcom_errstr = "Could not create Thumbnail File Attachment: " . mgd_errstr(); 364 361 debug_add($midcom_errstr, MIDCOM_LOG_ERROR); … … 368 365 369 366 $dest = mgd_open_attachment($thumb_id); 370 if (!$dest) { 367 if (!$dest) 368 { 371 369 $midcom_errstr = "Could not open Thumbnail File Attachment for writing: " . mgd_errstr(); 372 370 debug_add($midcom_errstr, MIDCOM_LOG_ERROR); … … 375 373 } 376 374 $source = fopen($file_tmp_thumb,"r"); 377 if (!$source) { 375 if (!$source) 376 { 378 377 $midcom_errstr = "Could not open scaled image for reading, aborting thumbnail creation."; 379 378 debug_add($midcom_errstr, MIDCOM_LOG_ERROR); … … 383 382 return $id; 384 383 } 385 while (! feof($source)) 384 while (! feof($source)) 385 { 386 386 fwrite($dest, fread($source, 100000)); 387 } 387 388 388 389 /* clean up */ … … 395 396 $thumb_att = mgd_get_attachment($thumb_id); 396 397 $thumb_att->parameter("midcom.helper.datamanager.datatype.image","parent_guid",$att->guid()); 397 if ($new_x && $new_y) { 398 if ($new_x && $new_y) 399 { 398 400 $thumb_att->parameter("midcom.helper.datamanager.datatype.blob","size_x",$new_x); 399 401 $thumb_att->parameter("midcom.helper.datamanager.datatype.blob","size_y",$new_y); trunk/lib/midcom/services/indexer/document_attachment.php
r981 r1011 180 180 function _process_mime_word() 181 181 { 182 if ( ! @exec('which catdoc'))182 if (is_null($GLOBALS['midcom_config']['utility_catdoc'])) 183 183 { 184 184 debug_add('Could not find catdoc, indexing as binary.', MIDCOM_LOG_INFO); … … 192 192 $encoding = (strtoupper($this->_i18n->get_current_charset()) == 'UTF-8') ? 'utf-8' : '8859-1'; 193 193 194 $command = " catdoc-d{$encoding} -a $wordfile > $txtfile";194 $command = "{$GLOBALS['midcom_config']['utility_catdoc']} -d{$encoding} -a $wordfile > $txtfile"; 195 195 debug_add("Executing: {$command}"); 196 196 exec ($command, $result, $returncode); … … 213 213 function _process_mime_pdf() 214 214 { 215 if ( ! @exec('which pdftotext'))215 if (is_null($GLOBALS['midcom_config']['utility_pdftotext'])) 216 216 { 217 217 debug_add('Could not find pdftotext, indexing as binary.', MIDCOM_LOG_INFO); … … 225 225 $encoding = (strtoupper($this->_i18n->get_current_charset()) == 'UTF-8') ? 'UTF-8' : 'Latin1'; 226 226 227 $command = " pdftotext-enc {$encoding} -nopgbrk -eol unix $pdffile $txtfile 2>&1";227 $command = "{$GLOBALS['midcom_config']['utility_pdftotext']} -enc {$encoding} -nopgbrk -eol unix $pdffile $txtfile 2>&1"; 228 228 debug_add("Executing: {$command}"); 229 229 exec ($command, $result, $returncode); … … 244 244 function _process_mime_richtext() 245 245 { 246 if ( ! @exec('which unrtf'))246 if (is_null($GLOBALS['midcom_config']['utility_unrtf'])) 247 247 { 248 248 debug_add('Could not find unrtf, indexing as binary.', MIDCOM_LOG_INFO); … … 257 257 258 258 // Kill the first five lines, they are crap from the converter. 259 $command = " unrtf--nopict --text $rtffile | sed '1,5d' > $txtfile";259 $command = "{$GLOBALS['midcom_config']['utility_unrtf']} --nopict --text $rtffile | sed '1,5d' > $txtfile"; 260 260 debug_add("Executing: {$command}"); 261 261 exec ($command, $result, $returncode); trunk/lib/net/siriux/photos/Photo.php
r949 r1011 567 567 $geometry = escapeshellarg("{$width}x{$height}"); 568 568 $tmpfile = tempnam ("/tmp", "net_siriux_photos"); 569 $cmd = " convert " . escapeshellarg($filename)569 $cmd = "{$GLOBALS['midcom_config']['utility_imagemagick_base']}convert " . escapeshellarg($filename) 570 570 . " -geometry $geometry -quality 80 +profile '*' -colorspace RGB" 571 571 . ' -unsharp 1x5 -modulate 100,110,100 -gamma 0.95' … … 726 726 * @return bool Indicating success. 727 727 */ 728 function _getExifData($file = FALSE) { 729 if (! $file) { 728 function _getExifData($file = FALSE) 729 { 730 if (! $file) 731 { 730 732 $tmpfile = $this->_writeFullscaleFile(); 731 733 if (! $tmpfile) 732 734 return FALSE; 733 } else { 735 } 736 else 737 { 734 738 $tmpfile = $file; 735 739 } 736 740 737 741 $mode = "timestamp"; 738 $have_jhead = @exec("which jhead");742 $have_jhead = ! is_null($GLOBALS['midcom_config']['utility_jhead']); 739 743 $have_php = function_exists("read_exif_data"); 740 744 741 745 /* Detect operation mode, first check for PHP Version */ 742 if (substr(phpversion(),3) == "4.0" || version_compare(phpversion(), "4.2.0", "<")) { 746 if (substr(phpversion(),3) == "4.0" || version_compare(phpversion(), "4.2.0", "<")) 747 { 743 748 /* We have a version piror 4.2.0. exifread might be broken there. */ 744 749 if ($have_jhead) 750 { 745 751 $mode = "jhead"; 752 } 746 753 else if ($have_php) 754 { 747 755 $mode = "php"; 748 } else { 756 } 757 } 758 else 759 { 749 760 if ($have_php) 761 { 750 762 $mode = "php"; 763 } 751 764 else if ($have_jhead) 765 { 752 766 $mode = "jhead"; 767 } 753 768 } 754 769 … … 758 773 $force = $this->_config->get("force_exif_reader"); 759 774 if ($force == "php" && $have_php) 775 { 760 776 $mode = "php"; 777 } 761 778 else if ($force == "jhead" && $have_jhead) 779 { 762 780 $mode = "jhead"; 781 } 763 782 764 783 debug_add("Trying EXIF Reader mode $mode"); … … 769 788 $this->_getExifDataPHP($tmpfile); 770 789 if (! $this->_config->get("disable_autosync_created")) 790 { 771 791 $this->syncArticleCreated(); 792 } 772 793 break; 794 773 795 case "jhead": 774 796 $this->_getExifDataJhead($tmpfile); 775 797 if (! $this->_config->get("disable_autosync_created")) 798 { 776 799 $this->syncArticleCreated(); 800 } 777 801 break; 802 778 803 case "timestamp": 779 804 $this->_getExifDataTimestamp($tmpfile); 780 805 break; 806 781 807 default: 782 808 die ("Unknown EXIF Reader selected, this should not happen."); … … 831 857 * @param string file The file from which to get the EXIF data. 832 858 */ 833 function _getExifDataJhead($file) { 834 exec("jhead ".escapeshellarg($file), $return, $status); 835 $exif = Array (); 836 if ($status == 0) { 837 while (list($key,$value) = each ($return)) { 838 if (trim($value)) { 859 function _getExifDataJhead($file) 860 { 861 exec("{$GLOBALS['midcom_config']['utility_jhead']} " . escapeshellarg($file), $return, $status); 862 $exif = Array (); 863 if ($status == 0) 864 { 865 foreach ($return as $key => $value) 866 { 867 if (trim($value)) 868 { 839 869 $explodeReturn = explode(':', $value, 2); 840 if (isset($exif[trim($explodeReturn[0])])) { 841 $exif[trim($explodeReturn[0])] .= "<br>" . 842 trim($explodeReturn[1]); 843 } else { 844 $exif[trim($explodeReturn[0])] = 845 trim($explodeReturn[1]); 870 if (isset($exif[trim($explodeReturn[0])])) 871 { 872 $exif[trim($explodeReturn[0])] .= "<br>" . trim($explodeReturn[1]); 873 } 874 else 875 { 876 $exif[trim($explodeReturn[0])] = trim($explodeReturn[1]); 846 877 } 847 878 } 848 879 } 849 } else { 880 } 881 else 882 { 850 883 debug_add("No EXIF Data found, so not setting anything."); 851 884 $taken = 0; 852 885 } 853 886 854 if (! array_key_exists("Date/Time", $exif)) { 887 if (! array_key_exists("Date/Time", $exif)) 888 { 855 889 debug_add("EXIF Date not found, so not setting it."); 856 890 $taken = 0; … … 859 893 // replace silly colons in EXIF dates 860 894 $date = preg_replace("/(\d{4}):(\d{2}):(\d{2}) (\d{2}):(\d{2}):(\d{2})/", '\1-\2-\3 \4:\5:\6', $exif["Date/Time"]); 861 if (! $date) { // unkown date format 895 if (! $date) 896 { 897 // unkown date format 862 898 debug_add("Could not transform EXIF-Date into an ISO Timestamp, ignoring it."); 863 899 $taken = 0; trunk/lib/net/siriux/photos/admin.php
r936 r1011 86 86 87 87 88 function can_handle($argc, $argv) { 88 function can_handle($argc, $argv) 89 { 89 90 debug_push($this->_debug_prefix."can_handle"); 90 91 … … 94 95 $GLOBALS["midcom"]->set_custom_context_data("errstr", $this->errstr); 95 96 96 /* check if "convert" is installed */97 $convert = exec("which convert");98 if ($convert == "")99 {100 $midcom_errstr = "Could not find image convert utility in path.";101 debug_add($midcom_errstr, MIDCOM_LOG_ERROR);102 debug_add("Leaving");103 debug_pop();104 $GLOBALS["midcom"]->generate_error(MIDCOM_ERRCRIT, "Could not find image convert utility in path. Aborting.");105 return false;106 }107 108 97 debug_pop(); 109 98 … … 113 102 } 114 103 115 switch ($argv[0]) { 104 switch ($argv[0]) 105 { 116 106 case "upload": 117 107 case "config": … … 137 127 138 128 139 function handle($argc, $argv) { 129 function handle($argc, $argv) 130 { 140 131 debug_push($this->_debug_prefix . "handle"); 141 132 … … 454 445 $uploadtempdir = "/tmp/net.siriux.photos.upload." . time() . "." . getmypid(); 455 446 456 switch ($file_extension) { 447 switch ($file_extension) 448 { 457 449 case "zip": 458 450 $compressed = true; 459 451 $unzipcmd = 460 'unzip '452 "{$GLOBALS['midcom_config']['utility_unzip']} " 461 453 . escapeshellarg($file['tmp_name']) 462 454 . " -d{$uploadtempdir}"; … … 467 459 $compressed = true; 468 460 $unzipcmd = 469 "cd {$uploadtempdir} ; tar-xzf "461 "cd {$uploadtempdir} ; {$GLOBALS['midcom_config']['utility_tar']} -xzf " 470 462 . escapeshellarg($file["tmp_name"]); 471 463 break; … … 501 493 502 494 $find_result = Array(); 503 exec(" find{$uploadtempdir} -type f", $find_result);495 exec("{$GLOBALS['midcom_config']['utility_find']} {$uploadtempdir} -type f", $find_result); 504 496 foreach ($find_result as $fullname) 505 497 { … … 691 683 function check_uploaded_image ($filename) 692 684 { 693 $cmd = 'identify ' . escapeshellarg($filename) . ' 2>&1'; 685 $cmd = "{$GLOBALS['midcom_config']['utility_imagemagick_base']}identify " 686 . escapeshellarg($filename) . ' 2>&1'; 694 687 debug_add("Executing: {$cmd}"); 695 688 exec ($cmd, $output, $return); 696 if ($return != 0)689 if ($return !== 0) 697 690 { 698 691 debug_add("Check of image {$filename} failed, imagemagick return exit code {$return}", MIDCOM_LOG_INFO); trunk/lib/net/siriux/photos/filter.php
r762 r1011 11 11 12 12 /** 13 * Image Filter Class 13 * Image Filter Class, used to post process all images, check the documentation 14 * of the individual methods. 15 * 16 * @todo Document 14 17 * 15 18 * @author Eero af Heurlin, Nemein Oy <eero.afheurlin@nemein.com> … … 19 22 * @package net.siriux.photos 20 23 */ 21 class net_siriux_photos_imagefilter { 24 class net_siriux_photos_imagefilter 25 { 22 26 23 27 /** … … 42 46 * The constructor does a bit of variable initialization 43 47 */ 44 function net_siriux_photos_imagefilter() { 48 function net_siriux_photos_imagefilter() 49 { 45 50 $this->_filename = null; 46 51 $this->_quality = "-quality 90"; … … 61 66 * @returns true, if the file is valid, false otherwise. 62 67 */ 63 function set_file($filename) { 64 if (! is_writeable($filename)) { 68 function set_file($filename) 69 { 70 if (! is_writeable($filename)) 71 { 65 72 debug_add("The File {$filename} is not writeable.", MIDCOM_LOG_INFO); 66 73 return false; … … 80 87 * @returns true, if all filters have been successfully applied, false otherwise. 81 88 */ 82 function process_chain($chain) { 89 function process_chain($chain) 90 { 83 91 $filters = explode(";", $chain); 84 92 85 foreach ($filters as $cmd) { 86 if (!$this->process_command($cmd)) { 93 foreach ($filters as $cmd) 94 { 95 if (!$this->process_command($cmd)) 96 { 87 97 debug_add("Execution of {$cmd} failed, aborting now."); 88 98 return false; … … 108 118 * @returns true, if the filter executed successfully, false otherwise. 109 119 */ 110 function process_command($cmd) { 120 function process_command($cmd) 121 { 111 122 debug_add("Parsing command {$cmd}"); 112 123 $i = preg_match('/([a-z_]*)\(([^)]*)\)/', $cmd, $matches); 113 if (! $i) { 124 if (! $i) 125 { 114 126 debug_add("Failed to parse command {$cmd}, aborting.", MIDCOM_LOG_INFO); 115 127 return false; … … 120 132 debug_print_r("Have to execute {$command} with these arguments:", $args); 121 133 122 switch ($command) { 134 switch ($command) 135 { 123 136 case "gamma": 124 137 if (array_key_exists(0, $args) && $args[0] > 0) … … 165 178 * the transformed image to. Has to be managed by the callee. 166 179 */ 167 function _get_tempfile() { 180 function _get_tempfile() 181 { 168 182 return tempnam("/tmp", "net_siriux_photos"); 169 183 } … … 173 187 * of $tmpfile, deleting the temporary file afterwards. 174 188 */ 175 function _process_tempfile($tmpname) { 189 function _process_tempfile($tmpname) 190 { 176 191 $src = fopen($tmpname, "r"); 177 192 $dst = fopen($this->_filename, "w+"); 178 while (! feof($src)) { 193 while (! feof($src)) 194 { 179 195 $buffer = fread($src, 131072); /* 128 kB */ 180 196 fwrite($dst, $buffer, 131072); … … 231 247 * @returns true on success. 232 248 */ 233 function gamma($gamma) { 234 $cmd = "mogrify {$this->_quality} -gamma " . escapeshellarg($gamma) 235 . " " . escapeshellarg($this->_filename); 249 function gamma($gamma) 250 { 251 $cmd .= "{$GLOBALS['midcom_config']['utility_imagemagick_base']}mogrify {$this->_quality} -gamma " 252 . escapeshellarg($gamma) . " " . escapeshellarg($this->_filename); 236 253 237 254 exec($cmd, $output, $exit_code); 238 debug_print_r("Imagemagick returned with {$exit_code} and produced this output:", $output);239 240 if ($exit_code === 0){255 256 if ($exit_code === 0) 257 { 241 258 return true; 242 } else { 243 debug_add("ImageMagick failed to convert the image, see LOG_DEBUG for details.", MIDCOM_LOG_ERROR); 244 debug_add("Command was: {$cmd}"); 259 } 260 else 261 { 262 debug_add("ImageMagick failed to convert the image, it returned with {$exit_code}, see LOG_DEBUG for details.", MIDCOM_LOG_ERROR); 263 debug_print_r('The generated output was:', $output); 264 debug_add("Command was: [{$cmd}]"); 245 265 return false; 246 266 } … … 258 278 * @returns true on success. 259 279 */ 260 function exifrotate() { 261 if (! function_exists("read_exif_data")) { 280 function exifrotate() 281 { 282 if (! function_exists("read_exif_data")) 283 { 262 284 debug_add("read_exif_data required for exifrotate.", MIDCOM_LOG_ERROR); 263 285 return false; 264 286 } 265 287 $exif = read_exif_data($this->_filename); 266 if (! array_key_exists("Orientation", $exif)) { 288 if (! array_key_exists("Orientation", $exif)) 289 { 267 290 debug_add("EXIF information misses the orientation tag. Skipping.", MIDCOM_LOG_INFO); 268 291 return true; 269 292 } 270 if (! $exif || $exif["Orientation"] == 1) { 293 if (! $exif || $exif["Orientation"] == 1) 294 { 271 295 debug_add("No rotation neccessary."); 272 296 return true; … … 276 300 $imagesize = getimagesize($this->_filename); 277 301 278 if ($imagesize[2] == 2 && @exec("which jpegtran")) { 302 if ( $imagesize[2] == 2 303 && ! is_null($GLOBALS['midcom_config']['utility_jpegtran'])) 304 { 279 305 /* jpegtran */ 280 switch ($exif["Orientation"]) { 306 switch ($exif["Orientation"]) 307 { 281 308 case 2: $rotate = "-flip horizontal"; break; 282 309 case 3: $rotate = "-rotate 180"; break; … … 294 321 $tmpfile = $this->_get_tempfile(); 295 322 $do_unlink = true; 296 $cmd = "jpegtran -copy all {$rotate} -outfile {$tmpfile} " . escapeshellarg($this->_filename); 297 } else { 323 $cmd = "{$GLOBALS['midcom_config']['utility_jpegtran']} -copy all {$rotate} -outfile {$tmpfile} " . escapeshellarg($this->_filename); 324 } 325 else 326 { 298 327 /* Mogrify */ 299 328 debug_add("jpegtran not found, falling back to mogrify."); 300 329 301 switch ($exif["Orientation"]) { 330 switch ($exif["Orientation"]) 331 { 302 332 case 2: $rotate = "-flip"; break; 303 333 case 3: $rotate = "-rotate 180"; break; … … 313 343 } 314 344 315 $cmd = " mogrify {$this->_quality} {$rotate} "345 $cmd = "{$GLOBALS['midcom_config']['utility_imagemagick_base']}mogrify {$this->_quality} {$rotate} " 316 346 . escapeshellarg($this->_filename); 317 347 } 318 348 319 349 exec($cmd, $output, $exit_code); 320 debug_print_r("Imagemagick/jpegtran returned with {$exit_code} and produced this output:", $output); 321 322 if ($exit_code === 0) { 323 if ($do_unlink) 324 $this->_process_tempfile($tmpfile); 325 return true; 326 } else { 350 351 if ($exit_code !== 0) 352 { 327 353 debug_add("ImageMagick/jpegtran failed to convert the image, see LOG_DEBUG for details.", MIDCOM_LOG_ERROR); 328 debug_add("Command was: {$cmd}"); 329 if ($do_unlink) 330 unlink($tmpfile); 331 return false; 332 } 333 } 334 335 /** 336 * Manual image rotation 337 * 338 * Filter Syntax: rotate($rotate) 339 * 340 * Where $gamma is a positive floating point number greater then 0 341 * and less then 360; if omitted, a NULL operation is done. 342 * 343 * @param $rotate Degrees of rotation clockwise, negative amounts possible 344 * @returns true on success. 345 */ 346 function rotate($rotate) { 347 // Do some normalizing on the argument 348 while ($rotate < 0) 349 { 350 $rotate += 360; 351 } 352 while ($rotate > 360) 353 { 354 $rotate -= 360; 355 } 356 if ($rotate == 0 || $rotate == 360) 357 { 358 debug_add("Rotate is {$rotate}, we're happy as-is."); 359 // We're happy as-is :) 360 return true; 361 } 362 363 $do_unlink = false; 364 $imagesize = getimagesize($this->_filename); 365 366 // Try lossless jpegtran rotation if possible 367 if ( $imagesize[2] == 2 368 && ($rotate == 90 || $rotate == 180 || $rotate == 270) 369 && @exec("which jpegtran")) 370 { 371 $tmpfile = $this->_get_tempfile(); 372 $do_unlink = true; 373 $cmd = "jpegtran -copy all -rotate {$rotate} -outfile {$tmpfile} " . escapeshellarg($this->_filename); 374 } else { 375 /* Mogrify */ 376 debug_add("jpegtran not found or rotation incompatible, falling back to mogrify."); 377 378 $cmd = "mogrify {$this->_quality} -rotate {$rotate} " . escapeshellarg($this->_filename); 379 } 380 381 debug_add("We have to rotate clockwise by {$rotate} degrees, do_unlink: {$do_unlink}"); 382 debug_add("Executing: {$cmd}"); 383 exec($cmd, $output, $exit_code); 384 debug_print_r("Imagemagick/jpegtran returned with {$exit_code} and produced this output:", $output); 385 386 if ($exit_code === 0) 387 { 388 if ($do_unlink) 389 { 390 $this->_process_tempfile($tmpfile); 391 } 392 return true; 393 } 394 else 395 { 396 debug_add("ImageMagick/jpegtran failed to convert the image, see LOG_DEBUG for details.", MIDCOM_LOG_ERROR); 354 debug_print_r("Imagemagick/jpegtran returned with {$exit_code} and produced this output:", $output); 397 355 debug_add("Command was: {$cmd}"); 398 356 if ($do_unlink) … … 402 360 return false; 403 361 } 362 363 if ($do_unlink) 364 { 365 $this->_process_tempfile($tmpfile); 366 } 367 return true; 368 } 369 370 /** 371 * Manual image rotation 372 * 373 * Filter Syntax: rotate($rotate) 374 * 375 * Where $gamma is a positive floating point number greater then 0 376 * and less then 360; if omitted, a NULL operation is done. 377 * 378 * @param $rotate Degrees of rotation clockwise, negative amounts possible 379 * @returns true on success. 380 */ 381 function rotate($rotate) { 382 // Do some normalizing on the argument 383 while ($rotate < 0) 384 { 385 $rotate += 360; 386 } 387 while ($rotate > 360) 388 { 389 $rotate -= 360; 390 } 391 if ($rotate == 0 || $rotate == 360) 392 { 393 debug_add("Rotate is {$rotate}, we're happy as-is."); 394 // We're happy as-is :) 395 return true; 396 } 397 398 $do_unlink = false; 399 $imagesize = getimagesize($this->_filename); 400 401 // Try lossless jpegtran rotation if possible 402 if ( $imagesize[2] == 2 403 && ($rotate == 90 || $rotate == 180 || $rotate == 270) 404 && ! is_null($GLOBALS['midcom_config']['utility_jpegtran'])) 405 { 406 $tmpfile = $this->_get_tempfile(); 407 $do_unlink = true; 408 $cmd = "{$GLOBALS['midcom_config']['utility_jpegtran']} -copy all -rotate {$rotate} -outfile {$tmpfile} " . escapeshellarg($this->_filename); 409 } 410 else 411 { 412 /* Mogrify */ 413 debug_add("jpegtran not found or rotation incompatible, falling back to mogrify."); 414 415 $cmd = "{$GLOBALS['midcom_config']['utility_imagemagick_base']}mogrify {$this->_quality} -rotate {$rotate} " . escapeshellarg($this->_filename); 416 } 417 418 debug_add("We have to rotate clockwise by {$rotate} degrees, do_unlink: {$do_unlink}"); 419 exec($cmd, $output, $exit_code); 420 421 if ($exit_code !== 0) 422 { 423 debug_add("ImageMagick/jpegtran failed to convert the image, see LOG_DEBUG for details.", MIDCOM_LOG_ERROR); 424 debug_print_r("Imagemagick/jpegtran returned with {$exit_code} and produced this output:", $output); 425 debug_add("Command was: {$cmd}"); 426 if ($do_unlink) 427 { 428 unlink($tmpfile); 429 } 430 return false; 431 } 432 433 if ($do_unlink) 434 { 435 $this->_process_tempfile($tmpfile); 436 } 437 return true; 404 438 } 405 439 … … 421 455
