views:

23

answers:

1

Hi,

I display some data on my website and one of the data feed elements is an image.

[title] => Product title
[description] => some description
[image] => www.some-domain.com/product-image/p12345.jpg

I then display this image using

<img alt="product" src="<?=$data['image']?>" />

Most of the images are 80x80, 120x100 or other less than 150 in width, which perfectly fit in the website template, but some of them are quite large such as 800x600 which distort the layout. I want a control on these types.

I tried to set WIDTH="150", but as the width vary they dont look good. I was thinking If I could set a fixed width to images, say, larger than 250px then I can live with it for now. Any ideas how to achieve this?

Thanks

+3  A: 

I have used getimagesize() for exactly this.

$size = getimagesize( "http://www.some-domain.com/product-image/p12345.jpg" );
$width = $size[0];
$height = $size[1];
Greg
Don't forget to add the `http://` prefix in the image path; plus the `http` protocol wrapper must be enabled for this function to work.
Salman A
Thanks for spotting that - now corrected above.
Greg