retrieve image size to add it to the page

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
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

retrieve image size to add it to the page

Post by aneuryzma »

Hi,

I have the following image url:

Code: Select all

$imageURL = $_images_dir_.'/'.$images[$a]['filename'];
I need to know if the image from filesystem is a portrait or a landscape before to add it to the page with the right size.

How can I do it ?

thanks
webmonkey88
Forum Newbie
Posts: 20
Joined: Fri Aug 14, 2009 4:30 am

Re: retrieve image size to add it to the page

Post by webmonkey88 »

just done a quick google and found the function : getimagesize()

http://uk2.php.net/function.getimagesize

then once you have the height and width you should be ok.
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

Re: retrieve image size to add it to the page

Post by aneuryzma »

Hi,

thanks... I did it, but I don't get why my variables are empty... the url of the image is correct, I checked 3 times: it is relative to php file location.

Code: Select all

list($width1, $height1) = getimagesize('../../images/stories/'.$_images_dir_.'/'.$images[$a]['filename']);
 
echo $width1; //gives nothing
thanks
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

Re: retrieve image size to add it to the page

Post by aneuryzma »

hi,

is maybe a permission problem ?
when I print $width1, it is completely empty...

thanks
aneuryzma
Forum Contributor
Posts: 106
Joined: Sat May 17, 2008 7:03 am

Re: retrieve image size to add it to the page

Post by aneuryzma »

it was the wrong path (absolute /relative)
solved thanks
Post Reply