From f514f551121e6dd80372a87fb6ffa95c5b7a940e Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 23 Mar 2005 20:26:21 +0000 Subject: [PATCH] - Patch #18700 by Stefan and James: removed GD1 calls, improved error/status reporting, etc. --- includes/image.inc | 82 ++++++++++++++++++------------------ modules/system.module | 10 ++--- modules/system/system.module | 10 ++--- 3 files changed, 50 insertions(+), 52 deletions(-) diff --git a/includes/image.inc b/includes/image.inc index 4f852e4bc59..7d6ebeeb8c8 100644 --- a/includes/image.inc +++ b/includes/image.inc @@ -4,7 +4,7 @@ /** * Return a list of available toolkits. * - * @return An array of toolkit name => descriptive title + * @return An array of toolkit name => descriptive title. */ function image_get_available_toolkits() { $toolkits = file_scan_directory('includes', 'image\..*\.inc$'); @@ -18,7 +18,7 @@ function image_get_available_toolkits() { $output[$info['name']] = $info['title']; } } - $output['gd'] = t('Built-in GD Toolkit'); + $output['gd'] = t('Built-in GD2 toolkit'); return $output; } @@ -30,11 +30,12 @@ function image_get_available_toolkits() { function image_get_toolkit() { static $toolkit; if (!$toolkit) { - $toolkit = variable_get('image_toolkit', 'gd'); - if ($toolkit != 'gd') { - include_once 'includes/image.'. $toolkit .'.inc'; + $toolkit = variable_get('image_toolkit', 'gd2'); + $toolkit_file = 'includes/image.'.$toolkit.'.inc'; + if ($toolkit != 'gd' && file_exists($toolkit_file)) { + include_once $toolkit_file; } - elseif (!image_gd_settings()) { + elseif (!image_gd_check_settings()) { $toolkit = false; } } @@ -46,9 +47,9 @@ function image_get_toolkit() { * Invokes the given method using the currently selected toolkit. * * @param $method A string containing the method to invoke. - * @param $params An optional array of parameters to pass to the toolkit method + * @param $params An optional array of parameters to pass to the toolkit method. * - * @return Mixed values (typically Boolean for successful operation) + * @return Mixed values (typically Boolean for successful operation). */ function image_toolkit_invoke($method, $params = array()) { if ($toolkit = image_get_toolkit()) { @@ -57,7 +58,13 @@ function image_toolkit_invoke($method, $params = array()) { return call_user_func_array($function, $params); } else { - drupal_set_message(t('%method is not supported by %toolkit.', array('%method' => "$method", '%toolkit' => "$toolkit"))); + watchdog('php', t("The selected image handling toolkit '%toolkit' can not correctly process '%function'.", array('%toolkit' => "$toolkit", '%function' => "$function")), WATCHDOG_ERROR); + return false; + } + } + else { + if ($method == 'settings') { + return image_gd_settings(); } } } @@ -161,18 +168,36 @@ function image_crop($source, $destination, $x, $y, $width, $height) { } /** - * GD Toolkit functions + * GD2 toolkit functions + * With the minimal requirements of PHP 4.3 for Drupal, we use the build-in version of GD. */ /** - * Verify GD settings (that the extension is actually installed). + * Retrieve settings for the GD toolkit (not used). */ function image_gd_settings() { - if (!extension_loaded('gd')) { - drupal_set_message(t('Unable to load the GD toolkit'), 'error'); + if (image_gd_check_settings()) { + return t('The built-in GD toolkit is installed and working properly.'); + } + else { + form_set_error('image_toolkit', t("The built-in GD2 toolkit requires that the GD module for PHP be installed and configured properly. For more information see %url.", array('%url' => 'http://php.net/image'))); return false; } - return true; +} + +/** + * Verify GD2 settings (that the right version is actually installed). + * + * @return boolean + */ +function image_gd_check_settings() { + if ($check = get_extension_funcs('gd')) { + if (in_array('imagegd2', $check)) { + // GD2 support is available. + return true; + } + } + return false; } /** @@ -193,21 +218,8 @@ function image_gd_resize($source, $destination, $width, $height) { return false; } - // GD1 doesn't have true color - if (function_exists('imageCreateTrueColor')) { - $res = imageCreateTrueColor($width, $height); - } - else { - $res = imageCreate($width, $height); - } - - // GD1 doesn't have copyResampled - if (function_exists('imageCopyResampled')) { - imageCopyResampled($res, $im, 0, 0, 0, 0, $width, $height, $info['width'], $info['height']); - } - else { - imageCopyResized($res, $im, 0, 0, 0, 0, $width, $height, $info['width'], $info['height']); - } + $res = imageCreateTrueColor($width, $height); + imageCopyResampled($res, $im, 0, 0, 0, 0, $width, $height, $info['width'], $info['height']); $result = image_gd_close($res, $destination, $info['extension']); imageDestroy($res); @@ -235,7 +247,6 @@ function image_gd_rotate($source, $destination, $degrees, $bg_color = 0) { } $res = imageRotate($im, $degrees, $bg_color); - $result = image_gd_close($res, $destination, $info['extension']); return $result; @@ -251,17 +262,8 @@ function image_gd_crop($source, $destination, $x, $y, $width, $height) { } $im = image_gd_open($source, $info['extension']); - - // GD1 doesn't have true color - if (function_exists('imageCreateTrueColor')) { - $res = imageCreateTrueColor($width, $height); - } - else { - $res = imageCreate($width, $height); - } - + $res = imageCreateTrueColor($width, $height); imageCopy($im, $res, 0, 0, $x, $y, $width, $height); - $result = image_gd_close($res, $destination, $info['extension']); imageDestroy($res); diff --git a/modules/system.module b/modules/system.module index e3c5b5ecdb2..0fe36ee2981 100644 --- a/modules/system.module +++ b/modules/system.module @@ -241,15 +241,13 @@ function system_view_general() { $group = ''; $toolkits_available = image_get_available_toolkits(); if (count($toolkits_available) > 1) { - $group .= form_radios(t('Select an image processing toolkit'), 'image_toolkit', variable_get('image_toolkit', image_get_toolkit()), $toolkits_available); - $group .= image_toolkit_invoke('settings'); + $group .= form_radios(t('Select an image processing toolkit'), 'image_toolkit', variable_get('image_toolkit', image_get_toolkit()), $toolkits_available); } - else { - $group .= t('

No image toolkits are installed.

'); + $group .= image_toolkit_invoke('settings'); + if ($group) { + $output .= form_group(t('Image handling'), $group); } - $output .= form_group(t('Image handling'), $group); - // date settings: $zones = _system_zonelist(); diff --git a/modules/system/system.module b/modules/system/system.module index e3c5b5ecdb2..0fe36ee2981 100644 --- a/modules/system/system.module +++ b/modules/system/system.module @@ -241,15 +241,13 @@ function system_view_general() { $group = ''; $toolkits_available = image_get_available_toolkits(); if (count($toolkits_available) > 1) { - $group .= form_radios(t('Select an image processing toolkit'), 'image_toolkit', variable_get('image_toolkit', image_get_toolkit()), $toolkits_available); - $group .= image_toolkit_invoke('settings'); + $group .= form_radios(t('Select an image processing toolkit'), 'image_toolkit', variable_get('image_toolkit', image_get_toolkit()), $toolkits_available); } - else { - $group .= t('

No image toolkits are installed.

'); + $group .= image_toolkit_invoke('settings'); + if ($group) { + $output .= form_group(t('Image handling'), $group); } - $output .= form_group(t('Image handling'), $group); - // date settings: $zones = _system_zonelist();