Exiftool is a command line tool used for reading and writing metadata in many file formats. It's written in Perl so it's platform-independent and can be used also as an library.
$ exiftool screenshot.png
ExifTool Version Number : 10.53
File Name : screenshot.png
Directory : .
File Size : 750 kB
File Modification Date/Time : 2017:06:13 22:34:05-04:00
File Access Date/Time : 2017:06:17 13:19:58-04:00
File Inode Change Date/Time : 2017:06:13 22:34:05-04:00
File Permissions : rw-r--r--
File Type : PNG
File Type Extension : png
MIME Type : image/png
Image Width : 1482
Image Height : 648
Bit Depth : 8
Color Type : RGB with Alpha
Compression : Deflate/Inflate
...
Primary Platform : Apple Computer Inc.
CMM Flags : Not Embedded, Independent
Device Manufacturer : APPL
Device Model :
...
Exif Image Width : 1482
Exif Image Height : 648
Image Size : 1482x648
Megapixels : 0.960