Old 15-11-2006, 13:40   #1 (permalink)
chris_bcn
Goodbye little old lady
 
chris_bcn's Avatar
 
Join Date: Jun 2005
Location: Geordie in SF
Posts: 339
Send a message via MSN to chris_bcn
php idiot

I'm desperately trying to learn php as I go along

I've been trawling through php.net for a couple of weeks and trying to cram as much php into my head as possible.

And so, my question - I'm trying to use getimagesize() function

I'm trying to get an image and it's width and height returned.

I define $brandingimg in each document, and want to have the image and the width and the height returned. I also want a way of putting alt and/or title text - I'm guess I can just put a variable $alt in there and define it in each page.

<?php
$image = "/i/$brandingimg";
$size = getimagesize("$image");
$height = $size[1];
$width = $size[0];
echo "<img src=\"$image\" height=\"$height\" width=\"$width\" />";
?>

The image is returned fine, but the height and width are empty.

Any help would be great
  Reply With Quote
Old 15-11-2006, 13:44   #2 (permalink)
smallbeer
I Ain't Losing Any Sleep™
 
Join Date: Apr 2003
Posts: 5,236
have you tried without quoting the $image variable?

Code:
$size = getimagesize($image);
__________________
That's fuckin' ingenious, if I understand it correctly. It's a Swiss fuckin' watch.
  Reply With Quote
Old 15-11-2006, 13:48   #3 (permalink)
chris_bcn
Goodbye little old lady
 
chris_bcn's Avatar
 
Join Date: Jun 2005
Location: Geordie in SF
Posts: 339
Send a message via MSN to chris_bcn
cheers for the idea - that didn't make any difference though unfortunately
  Reply With Quote
Old 15-11-2006, 14:00   #4 (permalink)
smallbeer
I Ain't Losing Any Sleep™
 
Join Date: Apr 2003
Posts: 5,236
try using an absolute file path instead then.
__________________
That's fuckin' ingenious, if I understand it correctly. It's a Swiss fuckin' watch.
  Reply With Quote
Old 15-11-2006, 14:13   #5 (permalink)
dtrenz
blam blam
 
dtrenz's Avatar
 
Join Date: Aug 2006
Location: ann arbor, mi usa
Posts: 527
yes, try absolute path, or try "i/$brandingimg" instead of "/i/$brandingimg"
  Reply With Quote
Old 15-11-2006, 14:37   #6 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,732
<?php
$size = getimagesize("/i/".$brandingimg);
$image = "/i/$brandingimg";
$height = $size[1];
$width = $size[0];
echo "<img src=\"$image\" height=\"$height\" width=\"$width\" />";
?>

Does this work?
__________________
  Reply With Quote
Old 15-11-2006, 14:48   #7 (permalink)
datahound
Spare Parts
 
datahound's Avatar
 
Join Date: Jan 2005
Location: Bracknell Forest
Posts: 4,732
or

<?php
$size = getimagesize("/i/$brandingimg");
$image = "/i/$brandingimg";
$height = $size[1];
$width = $size[0];
echo "<img src=\"$image\" height=\"$height\" width=\"$width\" />";
?>
__________________
  Reply With Quote
Old 15-11-2006, 15:43   #8 (permalink)
dtrenz
blam blam
 
dtrenz's Avatar
 
Join Date: Aug 2006
Location: ann arbor, mi usa
Posts: 527
Quote:
Originally Posted by datahound
$size = getimagesize("/i/".$brandingimg);

oh yeah!!! i think variables are only evaluated in double-quotes in an echo statement. so this should fix it. nice catch.
  Reply With Quote
Old 15-11-2006, 16:51   #9 (permalink)
chris_bcn
Goodbye little old lady
 
chris_bcn's Avatar
 
Join Date: Jun 2005
Location: Geordie in SF
Posts: 339
Send a message via MSN to chris_bcn
cheers all - seems to be working a treat now
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8