Index: branches/5.1.x/core/units/helpers/image_helper.php =================================================================== diff -u -r12657 -r13086 --- branches/5.1.x/core/units/helpers/image_helper.php (.../image_helper.php) (revision 12657) +++ branches/5.1.x/core/units/helpers/image_helper.php (.../image_helper.php) (revision 13086) @@ -1,6 +1,6 @@ 0 || $params['max_height'] > 0) { list ($params['target_width'], $params['target_height'], $needs_resize) = $this->GetImageDimensions($src_image, $params['max_width'], $params['max_height'], $params); @@ -90,8 +96,9 @@ } $src_path = dirname($src_image); + $transform_keys = Array ('crop_x', 'crop_y', 'fill', 'wm_filename'); - if ($needs_resize || array_key_exists('wm_filename', $params) && $params['wm_filename']) { + if ($needs_resize || array_intersect(array_keys($params), $transform_keys)) { // resize required OR watermarking required -> change resulting image name ! $dst_image = preg_replace('/^'.preg_quote($src_path, '/').'(.*)\.(.*)$/', $src_path . DIRECTORY_SEPARATOR . 'resized\\1_' . crc32(serialize($params)) . '.\\2', $src_image); if (!file_exists($dst_image) || filemtime($src_image) > filemtime($dst_image)) { @@ -156,12 +163,12 @@ list ($read_function, $write_function, $file_extension) = explode(':', $resize_map[$mime_type]); + // when source image has large dimensions (over 1MB filesize), then 16M is not enough + set_time_limit(0); + ini_set('memory_limit', -1); + $src_image_rs = @$read_function($src_image); if ($src_image_rs) { - // when source image has large dimensions (over 1MB filesize), then 16M is not enough - set_time_limit(0); - ini_set('memory_limit', -1); - $dst_image_rs = imagecreatetruecolor($params['target_width'], $params['target_height']); // resize target size if (($file_extension == 'gif') || ($file_extension == 'png')) { @@ -394,6 +401,11 @@ if (array_key_exists('crop_x', $params) || array_key_exists('crop_y', $params)) { // resize by smallest inverted radio $resize_by = $this->_getCropImageMinRatio($image_info, $dst_width, $dst_height); + + if ($resize_by === false) { + return Array ($orig_width, $orig_height, false); + } + $ratio = $resize_by == 'width' ? $width_ratio : $height_ratio; } else { @@ -423,7 +435,13 @@ { $width_ratio = $dst_width ? $image_info[0] / $dst_width : 1; $height_ratio = $dst_height ? $image_info[1] / $dst_height : 1; + $minimal_ratio = min($width_ratio, $height_ratio); + if ($minimal_ratio < 1) { + // ratio is less then 1, image will be enlarged -> don't allow that + return false; + } + return $width_ratio < $height_ratio ? 'width' : 'height'; }