Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.593 diff -u -F^f -r1.593 common.inc --- includes/common.inc 30 Nov 2006 08:13:31 -0000 1.593 +++ includes/common.inc 4 Dec 2006 22:53:04 -0000 @@ -960,6 +960,22 @@ function format_plural($count, $singular } /** + * Parse a given byte count. + * + * @param $size + * The size expressed as a number of bytes with optional SI size suffix + * (e.g. 2, 3K, 5M, 10G). + * @return + * An integer representation of the size. + */ +function parse_size($size) { + $suffixes = array('' => 1, 'K' => 1024, 'M' => 1024 * 1024, 'G' => 1024 * 1024 * 1024); + if (preg_match('/([0-9]+)\s*(K|M|G)?B?/i', $size, $match)) { + return $match[1] * $suffixes[drupal_strtoupper($match[2])]; + } +} + +/** * Generate a string representation for the given byte count. * * @param $size Index: modules/color/color.module =================================================================== RCS file: /cvs/drupal/drupal/modules/color/color.module,v retrieving revision 1.10 diff -u -F^f -r1.10 color.module --- modules/color/color.module 4 Dec 2006 22:52:27 -0000 1.10 +++ modules/color/color.module 4 Dec 2006 22:53:04 -0000 @@ -189,6 +189,23 @@ function color_scheme_form_submit($form_ } } + // Make sure enough memory is available, if PHP's memory limit is compiled in. + if (function_exists('memory_get_usage')) { + // Fetch source image dimensions. + $source = drupal_get_path('theme', $theme) .'/'. $info['base_image']; + list($width, $height) = getimagesize($source); + + // We need at least a copy of the source and a target buffer of the same + // size (both at 32bpp). + $required = $width * $height * 4 * 2; + $usage = memory_get_usage(); + $limit = parse_size(ini_get('memory_limit')); + if ($usage + $required > $limit) { + drupal_set_message(t('There is not enough memory available to PHP to change this theme\'s color scheme. You need at least %size more. Check the PHP documentation for more information.', array('%size' => format_size($usage + $required - $limit), '%url' => 'http://ca3.php.net/manual/en/ini.core.php#ini.sect.resource-limits'))); + return; + } + } + // Delete old files foreach (variable_get('color_'. $theme .'_files', array()) as $file) { @unlink($file);