By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,799 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,799 IT Pros & Developers. It's quick & easy.

How do I get the image height width when generating image from PHP (getimagesize does seem to work)

P: n/a
Hi,

Is it possible to obtain the width/ height of an image when that image
is dyanically created using a PHP script and passing GET attributes.
For example:

<img src="images/showImage.php?image_id=5" />

My images are created from images stored on the server, their paths
stored on in database table and retrieved using the GET image_id and
PHP script (showImage.php). Because the images are different sizes I
would like to be able to use a PHP function / class that can take an
image path and generate the IMG width and height attributes. This
would just tidy up the page when loading.

So when I try to use PHP 'getimagesize' like so:

$wh = getimagesize ($_SERVER['DOCUMENT_ROOT'] . "/images/showImage.php?
image_id=5");

.... I get an error saying that the file or directory does not exist:

Warning: getimagesize(/customersites/0/home/httpd/vhosts/
mydomain.co.uk/httpdocs/images/showImage.php?image_id=5): failed to
open stream: No such file or directory in /customersites/0/home/httpd/
vhosts/mydomain.co.uk/httpdocs/classes/html.class.php on line 11
I thin it may be the GET atttribute that is throwing it. How would I
go about doing this? Thanks

Burnsy

Mar 21 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
bizt wrote:
Hi,

Is it possible to obtain the width/ height of an image when that image
is dyanically created using a PHP script and passing GET attributes.
For example:

<img src="images/showImage.php?image_id=5" />

My images are created from images stored on the server, their paths
stored on in database table and retrieved using the GET image_id and
PHP script (showImage.php). Because the images are different sizes I
would like to be able to use a PHP function / class that can take an
image path and generate the IMG width and height attributes. This
would just tidy up the page when loading.

So when I try to use PHP 'getimagesize' like so:

$wh = getimagesize ($_SERVER['DOCUMENT_ROOT'] . "/images/showImage.php?
image_id=5");

... I get an error saying that the file or directory does not exist:

Warning: getimagesize(/customersites/0/home/httpd/vhosts/
mydomain.co.uk/httpdocs/images/showImage.php?image_id=5): failed to
open stream: No such file or directory in /customersites/0/home/httpd/
vhosts/mydomain.co.uk/httpdocs/classes/html.class.php on line 11
I thin it may be the GET atttribute that is throwing it. How would I
go about doing this? Thanks

Burnsy
Your problem is this loads the file but does not execute the PHP code.
To get the image size, you need a real image - not a PHP file that
generates an image.

Perhaps there's another way - but the only ways I can think of to do
this require either generating the image and storing it as a temporary
file on disk, or generating it in memory twice - once for the size and
once to display it.

But I consider both to be hacks.

Your problem is you actually have two calls from the browser. The first
one is for your main page, where you want the sizes. But the the
browser makes an independent call to get the image (from the <imgtag).
And there's no easy way to generate the image in memory on the first
call and keep it available for the second call (and know to delete it
later, of course).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 21 '07 #2

P: n/a
Your problem is this loads the file but does not execute the PHP code.
To get the image size, you need a real image - not a PHP file that
generates an image.
I see, that makes sense.

I have tried accessing it via HTTP and that seems to work. So:

$wh = getimagesize ("http://www.mydomain.com/images/showImage.php?
image_id=5");

That works and the width and height are calculated ... I may be able
to use that, will mess about with it in meantime. Cheers
Mar 22 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.