PDA

View Full Version : Image resizing without distorting the image



ksreeniv
Apr 13th, 2010, 10:56 PM
Hi,

I have a php page wherein it retrieves images of different sizes. I need to display all the images in a uniform format. I tried altering the size of the image by altering the width and height attributes but I am getting distorted images.

Kindly guide me on this.

Thanks in advance.

met
Apr 13th, 2010, 11:02 PM
http://shiftingpixel.com/2008/03/03/smart-image-resizer/

probably worth a look

you could also look at cropping the image using css/php and resizing all of them to a given width.

but working with images of varying dimensions isn't "easy" per se to get consistently accurate, non-distorted images. at least no method i've personally ever used.

mbaker
Apr 14th, 2010, 10:23 AM
I have a php page wherein it retrieves images of different sizes. I need to display all the images in a uniform format. I tried altering the size of the image by altering the width and height attributes but I am getting distorted images.

From your comment that if you set both height and width the images distort, I take it that the images have different aspect ratios. If that is the case then it will be impossible to get a completely uniform format (ie same size and width) without at least one compromise.

The simplest solutions to implement are to use a uniform width or a uniform height. That is set some thing like height="150" or width="100" but not both.

This will have all your images resized by the browser to be the same height or width with the other dimension being altered by the browser so that the image maintains its aspect ratio.

If you want images that are the same size (both width and height) you will need to in some way crop the images, which can be problematic when done automatically as the important part of the image will sometimes be in the area that gets cropped.

HTH.