Jump to content

Auto-fit an image into a div with width contraints using php??


Padgoi

Recommended Posts

Hi, so I have this website that allows users to post images into a specific div, however the div has certain width constraints and I don't want the users to post an image that stretches this div.  I want the div to automatically resize the image to fit within the width contraints of the div. 

 

I don't want to use overflow: hidden because that just hides the part of the image that doesn't fit in the div, I need it to automatically resize the image to fit into the div, kind of how a table can.  Any way to do this without recoding the entire script using tables?

or without GD setting image parameters

<?php
	$image = "http://www.me.com/images/image.jpg";
	$tempimg = 	getImageSize($image);
	$size = $tempimg[3];
	$size = explode("\"",$size);
	$width = $size[1];
	$height = $size[3];
while($height > 500 || $width > 500)
	{
		$width = .99*$width;
		$height = .99*$height;
	}
echo  "<img src=\"".$image."\" width=\"".$width."\" height=\"".$height."\" />
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.