Currently working on a site, which is using the proffessional features of ImageGen. So far the script is working fine for landscape images using the following:
<img src="/ImageGen.ashx?image={umbraco.library:GetMedia(mediaItem, '0')/umbracoFile}&height=189&constrain=true"><!-- //Uses height for thumbnail, then css to hide width > 190px -->
But on portrait images, the resized image fills the height of the box, but not the width. Using the following makes a perfect thumbnail, but does no maintain the aspect ratio.
<img
src="/ImageGen.ashx?image={umbraco.library:GetMedia(mediaItem,
'0')/umbracoFile}&width=190&height=189&crop=resize&valign=top
">//Creates thumbnail, but does not constrain-->
I was wondering what the best approach would be to cover both portrait and landscpace. Were no matter what size the initial image is. It is resized to the correct width and height, with no padding and maintains the ascpect ratio.
Your second example works perfectly for me. When you crop and specify both the height and width you'll get an image of the precise height and width, filled to the edges, without distorting the image in the process.
I've just double-checked it with ImageGen 2.5.2 and 2.5.7 without problem with portrait, landscape, and square images.
Some things that might interfere -- if your source image is smaller than either of the height or width dimensions you're asking for and you don't allow upsizing. Or perhaps you have a previously-cached version of the image on disk or in the browser so you aren't seeing the correct result (I always use the nocache=true option when testing until I settle on the correct parameters).
Thanks for this. Have updated the xslt to use the second option, along with enabling the upsizing. Now getting nice thumbnails. Also added valign=center&align=center to centre the cropped images.
Cropping landscape and portrait images
Hi,
Currently working on a site, which is using the proffessional features of ImageGen. So far the script is working fine for landscape images using the following:
But on portrait images, the resized image fills the height of the box, but not the width. Using the following makes a perfect thumbnail, but does no maintain the aspect ratio.
<img src="/ImageGen.ashx?image={umbraco.library:GetMedia(mediaItem, '0')/umbracoFile}&width=190&height=189&crop=resize&valign=top ">//Creates thumbnail, but does not constrain-->
I was wondering what the best approach would be to cover both portrait and landscpace. Were no matter what size the initial image is. It is resized to the correct width and height, with no padding and maintains the ascpect ratio.
Thanks,
Eddie
Hi, Eddie,
Your second example works perfectly for me. When you crop and specify both the height and width you'll get an image of the precise height and width, filled to the edges, without distorting the image in the process.
I've just double-checked it with ImageGen 2.5.2 and 2.5.7 without problem with portrait, landscape, and square images.
Some things that might interfere -- if your source image is smaller than either of the height or width dimensions you're asking for and you don't allow upsizing. Or perhaps you have a previously-cached version of the image on disk or in the browser so you aren't seeing the correct result (I always use the nocache=true option when testing until I settle on the correct parameters).
cheers,
doug.
Hi Doug,
Thanks for this. Have updated the xslt to use the second option, along with enabling the upsizing. Now getting nice thumbnails. Also added valign=center&align=center to centre the cropped images.
Cheers,
Eddie
is working on a reply...