From e73b1d9a880634fd76ae416a41b34013fc64db00 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Mon, 24 Sep 2007 00:48:59 -0400 Subject: [PATCH] refactored path_to_convert --- upload.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) 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') { -- 1.7.10.4