Getting image size based on header

Hi,

is there any library or gem to get image size (in pixels) based on
image headers. Image headers should contains bytes that describe image
size, which is different for different formats - jpg, png, gif
etc.

This size does not need to be same as actual size of image and this
vulnerabily can be used for attacks: