From e6289e711ee6fbfac25a24224046d9cf8e36aace Mon Sep 17 00:00:00 2001 From: Nathan Haug Date: Mon, 6 Dec 2010 05:39:35 +0000 Subject: [PATCH] #933444 by folkertdv and quicksketch: Filesize of image resized using ImageAPI not updated. --- filefield.module | 17 +++++++++++------ 1 files changed, 11 insertions(+), 6 deletions(-) diff --git a/filefield.module b/filefield.module index 5a0739e..ee28bc1 100644 --- a/filefield.module +++ b/filefield.module @@ -791,6 +791,8 @@ function filefield_validate_image_resolution(&$file, $maximum_dimensions = 0, $m // Check first that the file is an image. if ($info = image_get_info($file->filepath)) { if ($maximum_dimensions) { + $resized = FALSE; + // Check that it is smaller than the given dimensions. if ($info['width'] > $max_width || $info['height'] > $max_height) { $ratio = min($max_width/$info['width'], $max_height/$info['height']); @@ -807,20 +809,23 @@ function filefield_validate_image_resolution(&$file, $maximum_dimensions = 0, $m $res = imageapi_image_open($file->filepath); imageapi_image_scale($res, $max_width, $max_height); imageapi_image_close($res, $file->filepath); + $resized = TRUE; } // Try to resize the image to fit the dimensions. elseif (image_get_toolkit() && @image_scale($file->filepath, $file->filepath, $max_width, $max_height)) { - drupal_set_message(t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $maximum_dimensions))); - - // Clear the cached filesize and refresh the image information. - clearstatcache(); - $info = image_get_info($file->filepath); - $file->filesize = $info['file_size']; + $resized = TRUE; } else { $errors[] = t('The image is too large; the maximum dimensions are %dimensions pixels.', array('%dimensions' => $maximum_dimensions)); } } + + // Clear the cached filesize and refresh the image information. + if ($resized) { + drupal_set_message(t('The image was resized to fit within the maximum allowed dimensions of %dimensions pixels.', array('%dimensions' => $maximum_dimensions))); + clearstatcache(); + $file->filesize = filesize($file->filepath); + } } if ($minimum_dimensions && empty($errors)) { -- 1.7.4.1