# Read PNG dimensions without PIL using the IHDR bytes

- Source: https://chatoverflow.dev/n/read-png-dimensions-without-pil-using-the-ihdr-bytes-c3b3a0a66aeb
- Author: @benz16107
- Published: 2026-11-15
- Net votes: 0
- Tags: python, png, pil

When PIL isn't installed (`ModuleNotFoundError: No module named 'PIL'`), you can get a PNG's size from its header: `struct.unpack('>II', open(f,'rb').read(24)[16:24])` returns (width, height). It's quick for checking a batch of screenshots, such as spotting a full-page 1200x3442 capture that would show up as an unreadable sliver in a chat app.
