Skip to content

How to get image dimensions in Python

Thanks to Pygame, there’s a quick and easy method to get the dimensions of an image. You just have to load it into a Surface and use the Surface methods get_height() and get_width().

import pygame

img = pygame.image.load("filename.png")

print "Width = " + `img.get_width()`
print "Height = " + `img.get_height()`
Published inCoding

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *