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?

Link to comment
Share on other sites

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."\" />
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.