Index: branches/5.0.x/core/units/helpers/image_helper.php =================================================================== diff -u -r12734 -r12873 --- branches/5.0.x/core/units/helpers/image_helper.php (.../image_helper.php) (revision 12734) +++ branches/5.0.x/core/units/helpers/image_helper.php (.../image_helper.php) (revision 12873) @@ -1,6 +1,6 @@ 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 +157,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 +395,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 +429,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'; } Index: branches/5.0.x/core/units/images/image_tag_processor.php =================================================================== diff -u -r12734 -r12873 --- branches/5.0.x/core/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 12734) +++ branches/5.0.x/core/units/images/image_tag_processor.php (.../image_tag_processor.php) (revision 12873) @@ -1,6 +1,6 @@ Fields['ThumbPath']) && !$image_id ) { $object->SetDefaultValues(); - $object->SetDBField('Url', $parent_item->GetDBField('FullUrl')); - $object->SetDBField('AltName', $this->getItemTitle($parent_item)); - $object->SetDBFieldsFromHash($parent_item->GetFieldValues(), Array('SameImages', 'LocalThumb', 'ThumbPath', 'ThumbUrl', 'LocalImage', 'LocalPath')); - $object->Loaded = true; + if (is_null($parent_item->GetDBField('SameImages'))) { + // JOIN definetly failed, because it's not-null column + $object->Loaded = false; + } + else { + $object->SetDBField('Url', $parent_item->GetDBField('FullUrl')); + $object->SetDBField('AltName', $this->getItemTitle($parent_item)); + + $object->SetDBFieldsFromHash($parent_item->GetFieldValues(), Array('SameImages', 'LocalThumb', 'ThumbPath', 'ThumbUrl', 'LocalImage', 'LocalPath')); + $object->Loaded = true; + } + } else { // if requested image is not primary thumbnail - load it directly $id_field = $this->Application->getUnitOption($this->Prefix, 'ForeignKey'); @@ -140,7 +148,7 @@ // when image is uploaded to virtual field in main item, but not saved to db $object->SetDBField('ThumbPath', $image_src); - if (!$object->isLoaded()) { + if (!$object->isLoaded() && $image_src) { // set fields for displaing new image during main item suggestion with errors $fields_hash = Array ( 'Url' => '', @@ -221,34 +229,12 @@ if ($max_width > 0 || $max_height > 0 || $format) { $src_image = FULL_PATH.$object->GetDBField('ThumbPath'); + list ($max_width, $max_height) = $this->_transformParams($params, $max_width, $max_height); + if ($object->isLoaded() && file_exists($src_image)) { $image_helper =& $this->Application->recallObject('ImageHelper'); /* @var $image_helper ImageHelper */ - $resize_format = 'resize:' . $max_width . 'x' . $max_height; - - $crop = $this->SelectParam($params, 'Crop,crop'); - if ($crop) { - if (strpos($crop, ';') === false) { - $crop = 'c|c'; - } - - $max_width = (is_null($max_height) ? $max_width : $resize_format) . ';crop:' . $crop; - $max_height = null; - } - - $fill = $this->SelectParam($params, 'Fill,fill'); - if ($fill) { - $max_width = (is_null($max_height) ? $max_width : $resize_format) . ';fill:' . $fill; - $max_height = null; - } - - $watermark = $this->SelectParam($params, 'Watermark,watermark'); - if ($watermark) { - $max_width = (is_null($max_height) ? $max_width : $resize_format) . ';wm:' . $watermark; - $max_height = null; - } - return $image_helper->ResizeImage($src_image, $max_width, $max_height); } elseif ($use_default_image) { @@ -283,11 +269,48 @@ } } - // return Default Image or false if NOT specified + // return Default Image or false if NOT specified (only for case, when SameImages = 0) return $this->_getDefaultImage($params); } /** + * Transforms Image/ImageSrc aggregated tag parameters into ones, that ResizeImage method understands + * + * @param Array $params + * @param int $max_width + * @param int $max_height + * @return Array + */ + function _transformParams($params, $max_width = false, $max_height = false) + { + $resize_format = 'resize:' . $max_width . 'x' . $max_height; + + $crop = $this->SelectParam($params, 'Crop,crop'); + if ($crop) { + if (strpos($crop, ';') === false) { + $crop = 'c|c'; + } + + $max_width = (is_null($max_height) ? $max_width : $resize_format) . ';crop:' . $crop; + $max_height = null; + } + + $fill = $this->SelectParam($params, 'Fill,fill'); + if ($fill) { + $max_width = (is_null($max_height) ? $max_width : $resize_format) . ';fill:' . $fill; + $max_height = null; + } + + $watermark = $this->SelectParam($params, 'Watermark,watermark'); + if ($watermark) { + $max_width = (is_null($max_height) ? $max_width : $resize_format) . ';wm:' . $watermark; + $max_height = null; + } + + return Array ($max_width, $max_height); + } + + /** * Returns default full url to default images * * @param Array $params @@ -306,7 +329,7 @@ $base_url = rtrim($this->Application->BaseURL(), '/'); $sub_folder = $this->Application->isAdmin ? rtrim(IMAGES_PATH, '/') : THEMES_PATH; - if ($max_width > 0 || $max_height > 0) { + if (($max_width !== false) || ($max_height !== false)) { $image_helper =& $this->Application->recallObject('ImageHelper'); /* @var $image_helper ImageHelper */