473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

[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
Jul 17 '05 #1
3 1718
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: nmac | last post by:
Hi all, hopefully someone can offer some sagely advice regarding Production use of Jakarta's Tomcat. First, some brief background. My company have a servlet application that connects to a MySQL...
14
by: Jason Daly | last post by:
I'm a freshman at college as a computer science major. I'm not sure it has what I want. Does anyone know if a major commonly exists in web design (focusing in server side languages)? I want to...
5
by: QA | last post by:
http://www.quirksmode.org/js/iframe.html says document.getElementById('testiframe').src and frames.location.href work for all The exper is WRONG. here is my test: ...
3
by: bradsalmon | last post by:
Hi all, Sorry for the long post, but I don't know how else to explain this one. Just after some advice really as I'm finding it difficult to update a database. Currently this is running in...
0
by: Tim Tyannikov | last post by:
Now that the Required property of SoapHeaderAttribute is obsolete, how can I verify that my custom SOAP header is sent to my Web Service? If it possible, can someone please show me how to do it? ...
3
by: Tony | last post by:
I have a WebApp with 3 text boxes and 1 button, as described below. Can someone please explain why the bad scenarios are occurring and better still if they can be prevented or worked-around?...
8
by: STG | last post by:
Greetings, My group has an SDK that was developed 5 years ago with VC++ 6. Over the last years, the requests for a VS.NET SDK has reached critical mass and I am now in the process of doing that....
9
by: parag_paul | last post by:
Hi all I am seeing the following code in one place standalone line in some function , { (void*) new (h) Class_Name(xip, virobj, type, true); } Does it make h an object of the Class_Name...
13
by: terry.holland | last post by:
I have a three tiered CRM application (ASP.Net UI, VB.Net Business Layer & VB.Net Data Access Layer) that consists of number of classes. The application will be deployed to a number of clients. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.