pygame scale image

import pygame
picture = pygame.image.load(filename)
picture = pygame.transform.scale(picture, (1280, 720))

4
2

                                    import pygame

# Load picture
picture = pygame.image.load("your/file/directery.png") # choose a picture and spesefy directery

# Resize
picture = pygame.transform.scale(picture # spesefy the objekt, (100, 100))# here is the scale by pixels

4 (2 Votes)
0
5
2
John Kim 150 points

                                    image = pygame.image.load("path/to/file.png")  # load image

width, height = image.get_width(), image.get_height()  # get size
print(width, height)  # print size

"""
OUTPUT:
(50, 50)
"""

5 (2 Votes)
0
3
2
Anjsimmo 90 points

                                    """Load image"""
# I'm loading an image, but that does not matter.
surface = pygame.image.load("path/to/file.png").convert()
# Documentation for Surface.convert() and Surface.convert_alpha():
# https://www.pygame.org/docs/ref/surface.html#pygame.Surface.convert

"""Scale / resize surface"""
surface = pygame.transform.scale(surface=surface, size=(50, 50))
# In depth documentation:
# https://www.pygame.org/docs/ref/transform.html#pygame.transform.rotate

3 (2 Votes)
0
0
7
Prince Imran 105 points

                                    import pygame
import pygame.font

pygame.init()
size = (400,400)
screen = pygame.display.set_mode(size)
clock = pygame.time.Clock()

def blitRotate(surf, image, pos, originPos, angle):

    # calcaulate the axis aligned bounding box of the rotated image
    w, h       = image.get_size()
    box        = [pygame.math.Vector2(p) for p in [(0, 0), (w, 0), (w, -h), (0, -h)]]
    box_rotate = [p.rotate(angle) for p in box]
    min_box    = (min(box_rotate, key=lambda p: p[0])[0], min(box_rotate, key=lambda p: p[1])[1])
    max_box    = (max(box_rotate, key=lambda p: p[0])[0], max(box_rotate, key=lambda p: p[1])[1])

    # calculate the translation of the pivot 
    pivot        = pygame.math.Vector2(originPos[0], -originPos[1])
    pivot_rotate = pivot.rotate(angle)
    pivot_move   = pivot_rotate - pivot

    # calculate the upper left origin of the rotated image
    origin = (pos[0] - originPos[0] + min_box[0] - pivot_move[0], pos[1] - originPos[1] - max_box[1] + pivot_move[1])

    # get a rotated image
    rotated_image = pygame.transform.rotate(image, angle)

    # rotate and blit the image
    surf.blit(rotated_image, origin)

    # draw rectangle around the image
    pygame.draw.rect (surf, (255, 0, 0), (*origin, *rotated_image.get_size()),2)

font = pygame.font.SysFont('Times New Roman', 50)
text = font.render('image', False, (255, 255, 0))
image = pygame.Surface((text.get_width()+1, text.get_height()+1))
pygame.draw.rect(image, (0, 0, 255), (1, 1, *text.get_size()))
image.blit(text, (1, 1))
w, h = image.get_size()

angle = 0
done = False
while not done:
    clock.tick(60)
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
        elif event.type == pygame.KEYDOWN:
            if event.key==pygame.K_ESCAPE:
                done = True

    pos = (screen.get_width()//2, screen.get_height()//2)
    pos = (200, 200)

    screen.fill(0)
    blitRotate(screen, image, pos, (w//2, h//2), angle)
    angle += 1

    pygame.draw.line(screen, (0, 255, 0), (pos[0]-20, pos[1]), (pos[0]+20, pos[1]), 3)
    pygame.draw.line(screen, (0, 255, 0), (pos[0], pos[1]-20), (pos[0], pos[1]+20), 3)
    pygame.draw.circle(screen, (0, 255, 0), pos, 7, 0)

    pygame.display.flip()

pygame.quit()

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
pygame load images and scale it how to change the size od an image in pygame python pygame draw image with set size mpygame scale image rotate in pygame pygame rotate image around pivot pygame image dimensions scale an image pygame how to scale down pygame image pygame get image width how to resize and display an image in pygame pygame rotate image to mouse how to shrink a image in pygame how to rotate image to a angle in pygame how to rotate image pygame how to change the scale of a picture in pygame resize and imagepygame image scale pygame pygame image width pygame display and scale image pygame display and scale image on screen how to scale an image pygame can I set the width and the height of an image in pygame pygame convert size of image resize images in pygame set dimensions of image pygame get dimensions of image pygame scale an image up pygame how to rotate a image about a point in pygame how can we rotate a image about a point in pygame pygame.image shrink to size how to change the size of a pygame window with images pygame get dimensions of image how to strech image size in pygame how to reduce the dimensions of an image in pygame pygame resize picture pygame scale an image pygame reduce image size how to upscale image pygame how to decrease the image size in pygame pygame image rotate center size of pygame image pygame upscale image scale image to be smaller in pygame rescalse image pygame pygame pixel size resize an image in pygame how to scale a image in pygame pgygame resize image rotate image around center pygame how to make an image smaller in pygame scale image to window pygame scale images to window size pygame pygame how to scale image pygame change the size of image pygame get image scale how to change size of image in pygame pygame.image.load.width pygame rotate image around point how to change image size in pygame scale pygame pygame how to resize a pic to screen size pygame get size of imahe pygame dimensions of image can we change the resolution of an image in pygame? how to decrease size of an image in pygame pygame.transform.scale(pygame.image.load pygame latest version pygame.transform.scale(pygame.image.load pygame.transform.scale(pygame.image.load()) how to change the dimesions of an image pygame resize an image pygame can you change the size of an image in pygame set image size pygame setting size of image python pygame how to scale screen size to image in pygame how to modify screen size to picture pygame how to print image size in pygame how to set image size in pygame pygame scale an image down change size of image pygame change dimensions of a foto pygame how to shrink a picture pygame pygame scale all images pygame scale up image pygame rescale image how to scale image pygame pygame rotating how to change the size of a image python pygame rotate img pygame get image resolution in pygame rotater img pygame pygame change size of image pygame alter image size rescale image pygame change image sixe pygame rotate photo in pygame pygame set rotation of image set rotation of image pygame pygame resize iamge how to upscale an image pygame scaling images pygame setting the size of an image in pygame pygame how to resize an im how to resize pygame image how to rotate a image to mouse in pygame pygame set image size rotate image from center pygame how to rotate image through mouse in pygame pygame shrink image how to increase the size of image in pygame python pygame rotate function how to size up images in pygame how to change the size of an image pygame pygame how img chage size pygame change width of image how to set image size in python in pygame pygame crop image how to change the size of images pygame pygame get width of image how to rotate an image pygame pygame change image based on pixel size change the resolution of a picture in pygame resize img pygame pygame increase image size pygame rotate image around center how to change image size pygame pygame how to resize image how to downscale an image pygame scaling a pygame image how to get image size in pygame how to downscale an image in pygame pygame transform image sizez pygame get image size resize a picture pygame scale img pygame how to change capacity of image in pygame pygame image scaling how to rotate image in pygame how to rotate an image in pygame change size image pygame rotation image pygame how to scale images pygame pygame load image size shrink image pygame pygame resize an image how to rotate a picture in pygame pygame scale images load a pygame image with a certain size image.width pygame pygame image resolution resize image in pygame pygame resize image resolution rotate pygame set size of image in pygame how to change a images size in pygame pygame changing size of image pygame changingsize of image pygame size of i how to resize image pygame how to scale an image in pygame pygame draw blit image smaller enlarge a texture pygame pygame scale actually cutting off image pygame blit scale how to scale image in pygame how to stretch a surface in pygame how to resize an image pygame pygame how to resize an image to fullscreen pygame how to resize an image change the image size in pygame pygame.transform .rotate how ro resize an imag3e in pygame blit an image pygame at double size resizing images in pygame rotate a surface pygmae pygame.transform.flip rotating image pygame pygame transform rotate object how to rotate an image using rect and vector in pygame risizable image in pygame pygame rotate transform pygame image scaling too large resizing image pygame pygame.rotate memory rotate image crashing pygame how to shrink an image in pygame how to make image smaller pygame pygame.transform.rotozoom pygame how to change scale how to scale images in pygame better pygame.transform.scale how to make pygame.tranform.scale better pygame scale down image pygame load and scale pygame scale image 2x how to resize an image in python using pygame pygame image set size pygame.transform.scale() making an image smaller pygame transform an image on a surface pygame scale image to half how to change the size of imges in pygame scale pygame image how to resize image in pygame pygasme.scale how to rotate a sprite pygame how to shrink an image pygame pygame scale percentage pygame rotate image\ blit rotate pygame smooth transformation pygame rezise object pygame how to shrink image pygame pygame.transform.flip vs rotate pygame how do i scale an image by 1.5 pygame image scale how to shrink image size pygame transform image on load pygame pygame rotate a drawn rect scaling images in pgame pygame size of image resizing images pygame how to load images with pygame with scale pygame rotate sprite How to scale an image by 2 in Pygame rotate rect pygame how to rotate a image in pygame screen blit size transform image pygame ptgame rotate image pygame change surface size resize surface pygame pygame background image full screen pygame change image size how to change the size of an image in pygame pytgame.transform.rotate() pygame rotate surface how to alter image size pygame.blit pygame size of a scaled image pygame get size of scaled image how to resize image with pygame pygame zoom can you downsize a photo in pygame rotate an image pygame pygame surface get rotation pygame.transform pygame rotate object pygame load image at scale python pygame display image bigger change image size in pygame pygame.image.rotate pygame image rotation pygame rotating image transform size of picture pygame pygame.trasnform.scale resize pygame image pygame make smaller change size of image in pygame transform pygame rotate images in pygame pygame blit image smaller pygame how to increase image size pygame scale surface scale image in pygame pygame scale image to fit rectangle resize loaded image pygame image size pygame make image bigger pygame how to resize an image to smaller in pygame how to resize an image in pygame pygame scaling not working on full image how to size an image pygame pygame.transform.scale 2x Pygame image size pygame image stretch pygame stretch image how to increase the size of the image in pygame pygame image rotate how to make a cimage grow then shrink in pygame pygame image resize pygame transform rotate scale transformation image in pygame scale tranformation image in pygame tranformation image in pygame how to transform scale in pygame pygame scale how to resize a image pygame resize image pygame scaling pygame image pygame size rotate image pygaem how to scale and transform image pygame rotate image pygame pygame.transform.laplacian() transform scale pygame pygame change angle of image pygame.transform.rotate pygame set image rotation set rotation of image in pygame rotate image in pygame pygame rotation how to rotate img in pygame horizontaly how to rotate img in pygame pygame resize image how to resize images in pygame how to resize imgs in pygame scale pygame.Surface scale surface pygame pygame change angle images pygame rotate images pygame transform scale image pygame pygame scaling image pygame.transform.rotate() how to scale and rotate image in pygame pygame transform scale pygame blit rotation pygame image transform pygame transform scale example pygame.transform.scale pygame rotate how to rotate images in pygame transform.rotate pygame pygame.transform.recale pygame transform.flip pygame flip image pygame scale image image pygame transform position pygame rotate image
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source