JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
refactored path_to_convert
authorJason Woofenden <jason183@herkamire.com>
Mon, 24 Sep 2007 04:48:59 +0000 (00:48 -0400)
committerJason Woofenden <jason183@herkamire.com>
Mon, 24 Sep 2007 04:48:59 +0000 (00:48 -0400)
upload.php

index 46f8b3c..05e1866 100644 (file)
@@ -164,23 +164,23 @@ function save_uploaded_file($key, $path) {
 
 function path_to_convert() {
        if(!isset($GLOBALS['path_to_convert'])) {
-               $convert = '/usr/local/bin/convert';
-               if(!file_exists($convert)) {
-                       $convert = '/usr/bin/convert';
-               }
-               if(!file_exists($convert)) {
-                       $convert = `which convert`;
-               }
-               if($convert == '' || !file_exists($convert)) {
-                       die("can't find imagemagick's 'convert' program");
-               }
-
-               $GLOBALS['path_to_convert'] = $convert;
+               $GLOBALS['path_to_convert'] = _path_to_convert();
        }
 
        return $GLOBALS['path_to_convert'];
 }
-               
+
+function _path_to_convert() {
+       # relies on PHP's short-circuit mechanism
+       if(file_exists($convert = '/usr/local/bin/convert') ||
+          file_exists($convert = '/usr/bin/convert') ||
+          ($convert = `which convert` != '' && file_exists($convert))) {
+               return $convert;
+       } else {
+               die("can't find imagemagick's 'convert' program");
+       }
+}
+
 
 # returns new filename with .png extension
 function gif_to_png($filename, $new_filename = 'just change extension') {