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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bizt

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

    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?i mage_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?i mage_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

  • Jerry Stuckle

    #2
    Re: How do I get the image height width when generating image fromPHP (getimagesize does seem to work)

    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?i mage_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?i mage_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.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • bizt

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

      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.co m/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


      Comment

      Working...