From: Jason Woofenden Date: Mon, 24 Sep 2007 04:48:59 +0000 (-0400) Subject: refactored path_to_convert X-Git-Url: https://jasonwoof.com/gitweb/?p=wfpl.git;a=commitdiff_plain;h=e73b1d9a880634fd76ae416a41b34013fc64db00 refactored path_to_convert --- diff --git a/upload.php b/upload.php index 46f8b3c..05e1866 100644 --- a/upload.php +++ b/upload.php @@ -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') {