|
Posted by Jerry Stuckle on 03/21/07 03:30
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 <img> tag).
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.
jstucklex@attglobal.net
==================
Navigation:
[Reply to this message]
|