There is no reason to reinvent the wheel. You can use the identify program from ImageMagick to do that for you.
CodingCabbage commented: Thankyou, very helpful +0
TrustyTony commented: clear thinking +12
Gribouillis commented: good help +14
Gribouillis commented: I forgot about the tuple ! +14
jeremywduncan commented: Thank you. This homework is hard without a tutor! +0
TrustyTony commented: Observant +12