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

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

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On 29 Mar 2004 23:55:36 -0800, jf*********@netcourrier.com (jfsebastian) wrote:
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...


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('http://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="6894" 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 <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #2

P: n/a
Andy Hassall <an**@andyh.co.uk> wrote in message news:<d5********************************@4ax.com>. ..
On 29 Mar 2004 23:55:36 -0800, jf*********@netcourrier.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.


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 ?
:-/
Jul 17 '05 #3

P: n/a
On 31 Mar 2004 04:33:19 -0800, jf*********@netcourrier.com (jfsebastian) wrote:
Andy Hassall <an**@andyh.co.uk> wrote in message news:<d5********************************@4ax.com>. ..
On 29 Mar 2004 23:55:36 -0800, jf*********@netcourrier.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.
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 !


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.
Do you think that opening an image on a remote host may change
the results ?


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

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.