Page 1 of 1

GetImageSize - how does this work - mine doesn't

Posted: Thu Apr 19, 2012 6:13 am
by simonmlewis

Code: Select all

$size = getimagesize('$logo');
I am trying to gather the height of an image, so I can resize a box that uses said image as a background-image (because things appear over the top of it).

Code: Select all

<?php
include "dbconn.php";
$result = mysql_query ("SELECT * FROM static WHERE section = 'logo'");
$num_rows = mysql_num_rows($result);
if ($num_rows == 0)
{
echo " style='background-image: url(/images/logo.png);'";
}
while ($row = mysql_fetch_object($result))
      {
			echo " style='background-image: url(/images/pages/$row->image);'";
			$logo = $row->image;
      }
mysql_free_result($result);
mysql_close($sqlconn);
$size = getimagesize('$logo');
echo ">$size";
?>
This produces:
[text]Warning: getimagesize($logo) [function.getimagesize]: failed to open stream: No such file or directory in C:\xampp\phpMyAdmin\site\index.php on line 168
>[/text]

Line 168 is $size = getimagesize('$logo');

I've clearly done something wrong here.
I've also seen "list" queries for height, but cannot see how to put that into a variable, to know the $height, and then use that in my script.

Any help would be appreciated.

Re: GetImageSize - how does this work - mine doesn't

Posted: Thu Apr 19, 2012 6:16 am
by Celauran
Why do you have $logo in quotes?

Re: GetImageSize - how does this work - mine doesn't

Posted: Thu Apr 19, 2012 6:28 am
by simonmlewis
Because the script I found had something like that in quotes. Is that the wrong thing to do?

Even out of quotes I get:
[text]Warning: getimagesize(test.png) [function.getimagesize]: failed to open stream: No such file or directory in C:\xampp\phpMyAdmin\site\index.php on line 168
>[/text]

BINGO.

Code: Select all

list($width, $height, $type, $attr) = getimagesize("images/pages/$row->image");
Then echo or use $height.

Re: GetImageSize - how does this work - mine doesn't

Posted: Thu Apr 19, 2012 7:30 am
by social_experiment
Wouldn't it be easier to use the array returned by getimagesize()

Code: Select all

<?php
 $pic = getimagesize($logo);
 // height value would be in $pic[1]
?>

Re: GetImageSize - how does this work - mine doesn't

Posted: Thu Apr 19, 2012 8:04 am
by simonmlewis
Does mine (that works) work much harder?

Re: GetImageSize - how does this work - mine doesn't

Posted: Thu Apr 19, 2012 8:09 am
by social_experiment
Without a time test it's hard to say; but the function returns an array so why not use it, the code you use is also in the php manual so i guess the format is acceptable

Re: GetImageSize - how does this work - mine doesn't

Posted: Thu Apr 19, 2012 8:19 am
by Celauran
There won't be a performance difference between the two.