Page 1 of 1

[SOLVED] getimagesize() question

Posted: Tue Jun 13, 2006 10:01 am
by $var
I'm using getimagesize() to try and contrain an image uploaded by users.
Some use spaces in filename (eg: John Hughes Picture.jpg) which throws the code off,
but sometimes, even when the name is properly (eg: seasons_chris_full.jpg) the resize doesn't work...

For example, the constraints shouldn't allow an image to be wider or taller than 125px,
however, there is an image displaying as (72dpi) 1500 x 2100px...

Code: Select all

$ID = $memberresults[Mem_ID];
					  $ceo = $memberresults[Mem_CImage];					  
					  $image =  "http://www.advantageboard.com/Imi/Mem_Img/$ID/$ceo";               
					  if ($ceo == "none") {
					  }
					  else {
					  $size = getimagesize("$image");
					  }
					  
					   $height = $size[1];
					   $width = $size[1];
					 if ($width > 125)
						 {
							   $width = 125;
							   $percent = ($size[1] / $height);
							   $width = ($size[0] / $percent);
						 }
					 else if ($width > 125)
						 {
							   $width = 125;
							   $percent = ($size[0] / $width);
							   $height = ($size[1] / $percent);
						 }
					  
				    $imageCEO=$memberresults["Mem_CImage"];
					if(empty($imageCEO) || $imageCEO =="none" ){
				    echo ""; 
				    }
				    else { 
				    echo "<img src='$image' height='$height' align='left' width='$width' border='0' vspace='2' hspace='2' class='caltable'>";
			  	    }

Posted: Tue Jun 13, 2006 10:11 am
by feyd
rawurlencode($ceo)

Your $width and $height variables are set to the same entry. It's a good idea to floor() the calculated dimensions, and you have two instances of trying to work based on $width being greater than 125. You may want to see which is greater, $width or $height, then calculate from there.

Posted: Tue Jun 13, 2006 10:50 am
by $var
thanks, i used rawurlencode and that seems to work well, and i switched my calculations and they are working now too!
thanks feyd.

Code: Select all

$height = $size[1];
					   $width = $size[1];
					 if ($width > $height)
						 {
							   echo "width is greater than height";
							   $width = 125;
							   $percent = ($size[1] / $height);
							   $width = ($size[0] / $percent);
						 }
					 else 
						 {
							   $height = 250;
							   $percent = ($size[1] / $height);
							   $width = ($size[0] / $percent);
						 }

Posted: Tue Jun 13, 2006 10:53 am
by feyd
$width and $height are still being set to the same entry from $size.

Posted: Tue Jun 13, 2006 10:59 am
by $var

Code: Select all

$height = $size[1];
					   $width = $size[0];
better?

Posted: Tue Jun 13, 2006 1:04 pm
by John Cartwright
$var wrote:

Code: Select all

$height = $size[1];
					   $width = $size[0];
better?
You got it. :wink: