Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 697 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

How to read the firsts bytes of png,jpg and jpeg and get the height/width

Thread title: How to read the firsts bytes of png,jpg and jpeg and get the height/width
Reply    
    Thread tools Search this thread Display Modes  
07-12-2010, 01:20 PM
#1
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old  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

Reply With Quote
07-12-2010, 07:27 PM
#2
santa is offline santa
santa's Avatar
Status: Member
Join date: Mar 2009
Location: Location: location.
Expertise: Design, HTML
Software: Espresso, Photoshop, Mail.app
 
Posts: 398
iTrader: 7 / 100%
 

santa is on a distinguished road

Send a message via ICQ to santa Send a message via AIM to santa Send a message via MSN to santa Send a message via Yahoo to santa Send a message via Skype™ to santa

  Old

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?

Reply With Quote
07-12-2010, 07:59 PM
#3
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

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.

Reply With Quote
07-12-2010, 10:59 PM
#4
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old

Originally Posted by santa View Post
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 View Post
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

Reply With Quote
07-13-2010, 05:47 PM
#5
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

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?

Reply With Quote
07-14-2010, 05:27 PM
#6
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old

Originally Posted by Salathe View Post
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?

Reply With Quote
07-14-2010, 05:51 PM
#7
Salathe is offline Salathe
Salathe's Avatar
Status: Community Archaeologist
Join date: Jul 2004
Location: Scotland
Expertise: Software Development
Software: vim, PHP
 
Posts: 3,820
iTrader: 25 / 100%
 

Salathe will become famous soon enough

Send a message via MSN to Salathe

  Old

Then why were you looking for a faster way of getting the dimensions?

Reply With Quote
07-16-2010, 01:11 AM
#8
free-designer is offline free-designer
Status: Junior Member
Join date: Jun 2009
Location:
Expertise:
Software:
 
Posts: 98
iTrader: 0 / 0%
 

free-designer is on a distinguished road

  Old

Originally Posted by Salathe View Post
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 :-)

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed