Index: branches/RC/core/units/general/helpers/image_helper.php =================================================================== diff -u -N -r9252 -r9256 --- branches/RC/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 9252) +++ branches/RC/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 9256) @@ -3,6 +3,40 @@ class ImageHelper extends kHelper { /** + * Resized given image to required dimensions & saves resized image to "resized" subfolder in source image folder + * + * @param string $src_image full path to image (on server) + * @param mixed $max_width maximal allowed resized image width or false if no limit + * @param mixed $max_height maximal allowed resized image height or false if no limit + * @return string direct url to resized image + */ + function ResizeImage($src_image, $max_width, $max_height) + { + if ($max_width > 0 || $max_height > 0) { + list ($max_width, $max_height, $needs_resize) = $this->GetImageDimensions($src_image, $max_width, $max_height); + + if ($needs_resize) { + $src_path = dirname($src_image); + $dst_image = preg_replace('/^'.preg_quote($src_path, '/').'(.*)\.(.*)$/', $src_path.'/resized\\1_'.$max_width.'x'.$max_height.'.\\2', $src_image); + if (!file_exists($dst_image) || filemtime($src_image) > filemtime($dst_image)) { + // resized image not available OR should be recreated due source image change + $image_resized = $this->ScaleImage($src_image, $dst_image, $max_width, $max_height); + if (!$image_resized) { + // resize failed, because of server error + $dst_image = $src_image; + } + } + + // resize ok + $src_image = $dst_image; + } + } + + $base_url = rtrim($this->Application->BaseURL(), '/'); + return preg_replace('/^'.preg_quote(FULL_PATH, '/').'(.*)/', $base_url.'\\1', $src_image); + } + + /** * Proportionally resizes given image to destination dimensions * * @param string $src_image full path to source image (already existing)