[expert advice required][Is getImageSize really smart ?]

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

    [expert advice required][Is getImageSize really smart ?]

    Hi,

    I am wondering if getImageSize does fetch images
    *before* extracting the size infos (like perl
    modules...) or if the function only fetch the
    few bytes in the file headers which contains
    the size information ?

    I am trying to code a similar function in perl,
    and i think it is very stupid to have to fetch
    a 2Mo image to just retrieve its size...

    Need your help gurus...!

    Thanxs
  • Andy Hassall

    #2
    Re: [expert advice required][Is getImageSize really smart ?]

    On 29 Mar 2004 23:55:36 -0800, jfsebastian@net courrier.com (jfsebastian) wrote:
    [color=blue]
    >I am wondering if getImageSize does fetch images
    >*before* extracting the size infos (like perl
    >modules...) or if the function only fetch the
    >few bytes in the file headers which contains
    >the size information ?
    >
    >I am trying to code a similar function in perl,
    >and i think it is very stupid to have to fetch
    >a 2Mo image to just retrieve its size...[/color]

    From a quick glance at the source code, it looks like it should be bailing out
    once it's got all the header, and shouldn't have to fetch the whole image.

    But:

    <pre>
    <?php
    $x = getimagesize('h ttp://localhost/~andyh/j5_360.jpg');
    var_dump($x);
    ?>
    </pre>

    Output:

    array(7) {
    [0]=>
    int(6894)
    [1]=>
    int(963)
    [2]=>
    int(2)
    [3]=>
    string(25) "width="689 4" height="963""
    ["bits"]=>
    int(8)
    ["channels"]=>
    int(3)
    ["mime"]=>
    string(10) "image/jpeg"
    }

    (i.e. it's a pretty big image)

    Apache log shows:

    127.0.0.1 - - [30/Mar/2004:23:13:53 +0100] "GET /~andyh/j5_360.jpg HTTP/1.0"
    200 2833418 "-" "-"

    Which seems to say it's fetched all 2.8M of it :-(
    Apache's server-info page agrees, from the increase in Total Traffic.

    --
    Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
    http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

    Comment

    • jfsebastian

      #3
      Re: [expert advice required][Is getImageSize really smart ?]

      Andy Hassall <andy@andyh.co. uk> wrote in message news:<d5sj605e0 dtrk0t5krq7o3u4 rtd9i0hhkt@4ax. com>...[color=blue]
      > On 29 Mar 2004 23:55:36 -0800, jfsebastian@net courrier.com (jfsebastian) wrote:
      >
      > From a quick glance at the source code, it looks like it should be bailing out
      > once it's got all the header, and shouldn't have to fetch the whole image.
      >
      > But:
      >
      > ...
      >
      > (i.e. it's a pretty big image)
      >
      > Apache log shows:
      >
      > 127.0.0.1 - - [30/Mar/2004:23:13:53 +0100] "GET /~andyh/j5_360.jpg HTTP/1.0"
      > 200 2833418 "-" "-"
      >
      > Which seems to say it's fetched all 2.8M of it :-(
      > Apache's server-info page agrees, from the increase in Total Traffic.[/color]

      Tanks Andy for this test: very instructive, indeed.
      It is unbelievable that you have to fecth 2Mo to just read a few bytes...
      Even more surprising is that nobody thought about fopen(blabla)
      read the headers blabla and fclose and finished !

      Do you think that opening an image on a remote host may change
      the results ?
      :-/

      Comment

      • Andy Hassall

        #4
        Re: [expert advice required][Is getImageSize really smart ?]

        On 31 Mar 2004 04:33:19 -0800, jfsebastian@net courrier.com (jfsebastian) wrote:
        [color=blue]
        >Andy Hassall <andy@andyh.co. uk> wrote in message news:<d5sj605e0 dtrk0t5krq7o3u4 rtd9i0hhkt@4ax. com>...[color=green]
        >> On 29 Mar 2004 23:55:36 -0800, jfsebastian@net courrier.com (jfsebastian) wrote:
        >>
        >> From a quick glance at the source code, it looks like it should be bailing out
        >> once it's got all the header, and shouldn't have to fetch the whole image.
        >>
        >> But:
        >>
        >> ...
        >>
        >> (i.e. it's a pretty big image)
        >>
        >> Apache log shows:
        >>
        >> 127.0.0.1 - - [30/Mar/2004:23:13:53 +0100] "GET /~andyh/j5_360.jpg HTTP/1.0"
        >> 200 2833418 "-" "-"
        >>
        >> Which seems to say it's fetched all 2.8M of it :-(
        >> Apache's server-info page agrees, from the increase in Total Traffic.[/color]
        >
        >Tanks Andy for this test: very instructive, indeed.
        >It is unbelievable that you have to fecth 2Mo to just read a few bytes...
        >Even more surprising is that nobody thought about fopen(blabla)
        >read the headers blabla and fclose and finished ![/color]

        What's somewhat confusing is that this appears to be exactly what they tried
        to do in the source code.

        See ext/standard/image.c, php_handle_jpeg function. It's got a big switch
        statement for each token it goes through, with this near the end:

        case M_SOS:
        case M_EOI:
        return result; /* we're about to hit image data, or are at
        EOF. stop processing. */

        It then returns back to getimagesize, and closes the stream.
        Perhaps it's not hitting these cases? Probably needs some more testing and
        tracing to work out what's really going on.
        [color=blue]
        >Do you think that opening an image on a remote host may change
        >the results ?[/color]

        No, I don't - a URL is a URL, it doesn't know whether it's local or remote.

        --
        Andy Hassall <andy@andyh.co. uk> / Space: disk usage analysis tool
        http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space

        Comment

        Working...