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
Anyone, correct me if I'm wrong, but I don't think that's possible. Besides, you're making your life harder with that. getimagesize( ) was created for that purpose. Just do a: list($current_width, $current_height) = getimagesize($filename); PHP: And you're done. Stop making your life complicated.
@Rainulf: I know that, the problem is that this function is so slow that why i hate it. anyway im going to change my plans with my script cuz i can't find what i need thanks so mush
Just how is it slow? The dimensions of an image are already in the image itself, all the function does is grab it.
No, getimagesize() downloads all of the picture first from an remote url, that why it's slow it has to download it and then get the image height and width
Ahh I see, so that's your issue. There's imagesx( ) and imagesy( ), I haven't tried those two myself, but if I have to guess, they probably do the same as getimagesize( ). But figuring out with bytes alone wouldn't give us the image's height and width, at least that's what I think - I could be wrong. So here's my personal approach (i haven't tried it myself). The issue is - downloading the image to get its height and width is unavoidable. So why not just download a portion of it(use the imagecopy( ) function)? Say a pixel of width and a pixel of height. Then use those two functions I mentioned, imagesx( ) and imagesy( ). Theoroetically, it should decrease the downloading.
@Rainulf: Well, i guess you made a good point i'll check it out by my self, and if i came back with any results i'll post a comment back. Thanks Rainulf
Did you even read it? Everyone there said it's not possible with cURL. Anyway, free-designer, read the function made by one of the contributers: http://www.php.net/manual/en/function.getimagesize.php#88793 - I think that's it. I tried it myself, but it doesn't seem to work properly on my side. =/
No i didnt ... but why isnt it possible with curl instead of using the fucntion of php which downloads the whole image its better to use curl and transfer it to the server and then do the checking this would be faster