|
|
|
|
Thread title: How to read the firsts bytes of png,jpg and jpeg and get the height/width |
|
|
|
|
|
Thread tools
Search this thread
Display Modes
|
|
07-12-2010, 01:20 PM
|
#1
|
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
Posts: 98
|
How to read the firsts bytes of png,jpg and jpeg and get the height/width
Hey guys,
I was looking for a way to get the image height and width mush faster then using getimagesize();
so i thought that getting the first bytes of an image would be faster to get the height and width.
can anyone help me with the code that should do that for png,jpg and jpeg?
thanks so mush
|
|
07-12-2010, 10:59 PM
|
#3
|
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
Posts: 98
|
Originally Posted by santa
getimagesize() is probably the best way to go around finding an image's size.
You ever going to use this forum for anything OTHER than asking questions?
|
Thanks for you comment, but is there any law of talkfreelance sayting that i shouldn't always ask????
Originally Posted by Salathe
To confirm santa's suggestion, getimagesize() does exactly what you're looking for and will likely be as fast as you can get for doing this task.
The underlying C code for the function (for the common image types) literally reads the first few bytes of the file for the required width/height information; you can't get much more streamlined than that.
|
well i guess it's true, thanks salathe.
MOD note: merged
|
|
07-12-2010, 07:59 PM
|
#4
|
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
Posts: 3,820
|
To confirm santa's suggestion, getimagesize() does exactly what you're looking for and will likely be as fast as you can get for doing this task.
The underlying C code for the function (for the common image types) literally reads the first few bytes of the file for the required width/height information; you can't get much more streamlined than that.
|
|
07-13-2010, 05:47 PM
|
#5
|
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
Posts: 3,820
|
Is there any reason why you feel (or felt, at the time of posting this thread) why getimagesize() is not suited to the task of getting your images dimensions?
|
|
07-14-2010, 05:27 PM
|
#6
|
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
Posts: 98
|
Originally Posted by Salathe
Is there any reason why you feel (or felt, at the time of posting this thread) why getimagesize() is not suited to the task of getting your images dimensions?
|
No i didn't, why?
|
|
07-14-2010, 05:51 PM
|
#7
|
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
Posts: 3,820
|
Then why were you looking for a faster way of getting the dimensions?
|
|
07-16-2010, 01:11 AM
|
#8
|
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
Posts: 98
|
Originally Posted by Salathe
Then why were you looking for a faster way of getting the dimensions?
|
Im using regex with preg_match_all() to get all of the imgs tags on the passed url, my problem is that i want to validate the height and width. so it takes a lot of seconds to download only one image, so if there is a 30 imgs or something and all of them is 3megabyte or something. then it will take a looooot of time to read them, so i thought there would be a better way to get images height/width.
Thats why.
Thanks salathe :-)
|
|
|
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|