View Single Post
  #1 (permalink)  
Old Jun 6th, 2005, 17:16
jono jono is offline
Junior Member
Join Date: Jan 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Image Resize problem

I am trying to retrieve some images from a mySQL DB, resize them in PHP, in proportion, with the following function. This is working fine when testing on my local machine. However, when I load it to the web I get the default width($mw) but no height (IE draws a 1m image height). Check it out at
http://www.freewaymedical.co.uk/prot...dex.php?cat=ch

Thinking it must be differing PHP versions on local machine and web hosts. Is there anything I can edit in my code for a fix?

Code: Select all
//n=image name
//mh=maxHeight
//mw=maxwidth
function resizeGetSize($n, $mh, $mw){
//test for type String or object. This is so the function can handle
//objects directly
	//getimagesize() returns width and height in an array
	$imgSize = getimagesize($n); 
	
	$prop = $imgSize[0] / $mw;
	$newHeight=$imgSize[1] / $prop;
	
	//initialize a var to hold the max width of the img
	$newWidth=$mw;
	$decrement=5;

		//loop until the height of the image is less than 180 (so it fits in the cell with no fuss)
		while($newHeight>$mh){

			$prop = $imgSize[0] / ($newWidth-$decrement);
			$newHeight=($imgSize[1] / $prop);
			//take off 5 px at a time until the pics height fits in the table height
			$newWidth=$newWidth - $decrement;

		}
	//return in string that can  be used directly in function
	return "width=\"$newWidth\" height=\"$newHeight\"";
}
Any help would be much appreciated.
Reply With Quote