Getting width and height of an image in Pygame Last Updated : 23 Jul, 2025 Comments Improve Suggest changes 9 Likes Like Report Prerequisites: Pygame To use graphics in python programs we use a module called Pygame. Pygame provides high functionality for developing games and graphics in Python. Nowadays Pygame are very much popular to build simple 2D games. In order to run a program written in Python using Pygame module, a system must have Python installed with Pygame module. Following are the examples and steps needed to import the image using Pygame and get the height and width of that image. Image in used : Link to the image Dimensions : 200x200 Method 1 : Using get_width() and get_height() : The name of the function is explanatory enough as to what they are used for. Approach Import pygameCreate an image object using pygame.image.load("Provide image path here ") and store it in a variable.To get height of the image use image.get_height() method, here image is the variable in which image object is stored.Similarly, to get width of the image we use image.get_width() method, here image is the variable in which image object is stored.Print result. Example: Python3 # import pygame import pygame # creating image object image = pygame.image.load('/home/amninder/Pictures/Wallpapers/download.png') # get_height method return the height of the surface pixel, # in our case surface is image print("Height of image= " + str(image.get_height())) # get_width method return the width of the surface pixel, # in our case surface is image print("Width of image= " + str(image.get_width())) Output: Method 1 Method 2 : Using get_size() : This function is capable of returning dimensions of the image provided to it as reference as a tuple. Approach Import moduleCreate a display object using display.set_mode() method.Load image to a variable using image.load() method.Using blit() method to draw the image on display surface object.Use get_size() method to display image width and height, this get_size() method returns width and height in tuples. Eg. (200,400).Use display.flip() to display content,i.e. anything that is drawn on the display surface object will be displayed on the window when the function is called in program. Example: Python3 import pygame as py # Initiate pygame and the modules that comes with pygame py.init() # setting frame/window/surface with some dimensions window = py.display.set_mode((300, 300)) # to set title of pygame window py.display.set_caption("GFG") # creating image object image = py.image.load('/home/amninder/Pictures/Wallpapers/download.png') # to display size of image print("size of image is (width,height):", image.get_size()) # loop to run window continuously while True: window.blit(image, (0, 0)) # loop through the list of Event for event in py.event.get(): # to end the event/loop if event.type == py.QUIT: # it will deactivate the pygame library py.quit() quit() # to display when screen update py.display.flip() Output : Using method 2 Create Quiz Comment A amnindersingh1414 Follow 9 Improve A amnindersingh1414 Follow 9 Improve Article Tags : Technical Scripter Python Technical Scripter 2020 Python-PyGame Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like