A web page pointed to by a url contains many images(gif,png,jpg...), I just want to find the one with the largest size(eg: choose 1024x600 instead of 800x300) by Swift code.
Currently, I have to download all images locally and then get their sizes
I know that the size data of the image is actually only stored in its header, does this mean that I only need to download the small header data of the image to get its size?
If possible, how can I parse to the size of the image through its header data?
preferably Swift or C code, thanks! ;)
Or is there a better way to get the size of the image from web without downloading it locally? Please enlighten me, thank you!
Update:
I find some ruby code to do this:
PNG:
IO.read('image.png')[0x10..0x18].unpack('NN')
=> [713, 54]
GIF:
IO.read('image.gif')[6..10].unpack('SS')
=> [130, 50]
BMP:
d = IO.read('image.bmp')[14..28]
d[0] == 40 ? d[4..-1].unpack('LL') : d[4..8].unpack('SS')
Do these codes work? Thanks.