getimagesize/if statement problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davidtube
Forum Commoner
Posts: 79
Joined: Sun Mar 25, 2007 8:42 pm

getimagesize/if statement problem

Post by davidtube »

I have the following code which is supposed to make an image fit inside a 250x250 table cell.

Code: Select all

$imageinfo = getimagesize("$imagelocation");
         
$ix=$imageinfo[0];
$iy=$imageinfo[1];

if (iy>ix)
{
$nheight=$iy/$iy*250;
$nwidth=$ix/$iy*250;
$test="y";
}
else
{
$nheight=$iy/$ix*250;
$nwidth=$ix/$ix*250;
$test="x";
}
		echo "' width='".$nwidth."' height='".$nheight."'/></a></center>". $ix.$iy.$test."
When $ix and $iy are echoed, the correct numbers are produced, but the if statement always produces the results as if $iy is greater. Am I missing something simple?
User avatar
seppo0010
Forum Commoner
Posts: 47
Joined: Wed Oct 24, 2007 4:13 pm
Location: Buenos Aires, Argentina

Post by seppo0010 »

Am I missing something simple?
Really simple... you are not usign $ in the if =)

Code: Select all

if (iy>ix) 

// should be
if ($iy>$ix) 

// right now it works like
if ('iy'>'ix')
davidtube
Forum Commoner
Posts: 79
Joined: Sun Mar 25, 2007 8:42 pm

Post by davidtube »

:oops:
Thanks. It just need a fresh pair of eyes looking at it I suppose.
Post Reply