pygame scale image

Solutions on MaxInterview for pygame scale image by the best coders in the world

showing results for - "pygame scale image"
Harris
05 Jul 2019
1import pygame
2picture = pygame.image.load(filename)
3picture = pygame.transform.scale(picture, (1280, 720))
4
Diego
29 Nov 2017
1"""Load image"""
2# I'm loading an image, but that does not matter.
3surface = pygame.image.load("path/to/file.png").convert()
4# Documentation for Surface.convert() and Surface.convert_alpha():
5# https://www.pygame.org/docs/ref/surface.html#pygame.Surface.convert
6
7"""Scale / resize surface"""
8surface = pygame.transform.scale(surface=surface, size=(50, 50))
9# In depth documentation:
10# https://www.pygame.org/docs/ref/transform.html#pygame.transform.rotate
Jana
20 Oct 2017
1import pygame
2import pygame.font
3
4pygame.init()
5size = (400,400)
6screen = pygame.display.set_mode(size)
7clock = pygame.time.Clock()
8
9def blitRotate(surf, image, pos, originPos, angle):
10
11    # calcaulate the axis aligned bounding box of the rotated image
12    w, h       = image.get_size()
13    box        = [pygame.math.Vector2(p) for p in [(0, 0), (w, 0), (w, -h), (0, -h)]]
14    box_rotate = [p.rotate(angle) for p in box]
15    min_box    = (min(box_rotate, key=lambda p: p[0])[0], min(box_rotate, key=lambda p: p[1])[1])
16    max_box    = (max(box_rotate, key=lambda p: p[0])[0], max(box_rotate, key=lambda p: p[1])[1])
17
18    # calculate the translation of the pivot 
19    pivot        = pygame.math.Vector2(originPos[0], -originPos[1])
20    pivot_rotate = pivot.rotate(angle)
21    pivot_move   = pivot_rotate - pivot
22
23    # calculate the upper left origin of the rotated image
24    origin = (pos[0] - originPos[0] + min_box[0] - pivot_move[0], pos[1] - originPos[1] - max_box[1] + pivot_move[1])
25
26    # get a rotated image
27    rotated_image = pygame.transform.rotate(image, angle)
28
29    # rotate and blit the image
30    surf.blit(rotated_image, origin)
31
32    # draw rectangle around the image
33    pygame.draw.rect (surf, (255, 0, 0), (*origin, *rotated_image.get_size()),2)
34
35font = pygame.font.SysFont('Times New Roman', 50)
36text = font.render('image', False, (255, 255, 0))
37image = pygame.Surface((text.get_width()+1, text.get_height()+1))
38pygame.draw.rect(image, (0, 0, 255), (1, 1, *text.get_size()))
39image.blit(text, (1, 1))
40w, h = image.get_size()
41
42angle = 0
43done = False
44while not done:
45    clock.tick(60)
46    for event in pygame.event.get():
47        if event.type == pygame.QUIT:
48            done = True
49        elif event.type == pygame.KEYDOWN:
50            if event.key==pygame.K_ESCAPE:
51                done = True
52
53    pos = (screen.get_width()//2, screen.get_height()//2)
54    pos = (200, 200)
55
56    screen.fill(0)
57    blitRotate(screen, image, pos, (w//2, h//2), angle)
58    angle += 1
59
60    pygame.draw.line(screen, (0, 255, 0), (pos[0]-20, pos[1]), (pos[0]+20, pos[1]), 3)
61    pygame.draw.line(screen, (0, 255, 0), (pos[0], pos[1]-20), (pos[0], pos[1]+20), 3)
62    pygame.draw.circle(screen, (0, 255, 0), pos, 7, 0)
63
64    pygame.display.flip()
65
66pygame.quit()
67
Pedro
02 Jun 2020
1image = pygame.image.load("path/to/file.png")  # load image
2
3width, height = image.get_width(), image.get_height()  # get size
4print(width, height)  # print size
5
6"""
7OUTPUT:
8(50, 50)
9"""
Emma
11 Jan 2020
1#Start Libraries
2import pygame, sys
3from pygame.locals import *
4#End Libraries
5
6pygame.init() #We're initializing the script
7
8pygame.display.set_caption('Platform') #This is the name of the window
9window_size = (600,400) #The size of the window
10screen = pygame.display.set_mode(window_size) #Initializing the screen
11
12image_not_scaled = pygame.image.load('file_path.png').convert() #Importing the image
13image = pygame.transform.scale(image_not_scaled, (32, 32)) #You can insert whatever you want for example (64, 64)
14														   #It MUST be a tuple
15
16#Now we'll create the while loop
17run = True #With this we can control the script (stop it)
18while run: #For NOW itz a simple while true
19    screen.fill((255, 255, 255)) #Filling the screen with white
20    screen.blit(image, (0, 0)) #Blitting the image on the screen
21
22    for event in pygame.event.get(): #Checking the events
23        if event.type == QUIT: #Checking if the event is QUIT
24            pygame.quit() #In that case we'll exit from pygame
25            sys.exit() #In that case we'll exit from the script
26    
27    pygame.display.update() #Updating the screen
28
Lois
04 Feb 2017
1import pygame
2
3# Load picture
4picture = pygame.image.load("your/file/directery.png") # choose a picture and spesefy directery
5
6# Resize
7picture = pygame.transform.scale(picture # spesefy the objekt, (100, 100))# here is the scale by pixels
queries leading to this page
enlarge a texture pygamepygame rotate surfacepygame rotate image around centerhow to rotate a image in pygamewpygame how to change image sizehow to change size of image pygamehow to resize in pygamecan we change the resolution of an image in pygame 3frotate img pygamehow to rotate a image in pygamehow to change scale of an image in pygamepygame resize imaghehow to stretch a surface in pygameget image resolution in pygamescale an image pygamehow ro resize an imag3e in pygamescale transformation image in pygamepygame change angle imagespygame load images and scale ithow can we rotate a image about a point in pygamescale image pygametransform an image on a surfacehow to rotate an image in pygame around a pointpygame image scaling too largechange size image pygamepygame transform rotatehow to increase the size of an image in pygameload a pygame image with a certain sizehow to shrink a image in pygamescale surface pygamepygame get size of imagehow to change image size pygamehow to scale and transform image pygamepygame image resizehow to change size of a picture pygamepygame rotate image to mousepygame how to scale an imagepygame rotate objectpygame change width of imagesetting the size of an image in pygamecan you downsize a photo in pygamehow to change the scale of a picture in pygamepygame resize pnghow to downscale an image pygamehow to change the size of imges in pygamepygame blit rotationpygame how to scalepygame get dimensions of imagepygame display and scale image on screenpygame scale image to halfpygame transform scalepygame convert size of imagehow to changet the size of picture in pygame 5cpygame scalepygame transform scalerotate image around center pygamepygame transform recalepygame how to resize a pic to screen sizetransform size of picture pygamepygame resize image resolutionpygame rotate spritepygame image sizepygame rotate image rotate recntanlge image pygamehow to resize images in pygamehow to rotate images in pygamepygame stretch imagepygame surface get rotationpygame rotating imagepygame make an image rotate around a point outside the imagehow to scale images in pygamerotate image in pygamepygame rotationpygame resize iamgepygame display and scale imagepygame blit scalehow to set the scale of an image in pygamepygame how to resize an impygame sizehow to get an image size in pygameset image size pygamepygame transform image sizezpygame make window scaleablehow to downscale an image in pygamepygame image transform rotate 28 29setting size of image python pygamepygame rotate imagesresize image according to screen size pygamesize of pygame imageresize an image in pygamepygame rect rotatepygame rescale imagehow to resize pygame imagepygame scale actually cutting off imagepygame scaling imagehow to make an image smaller in pygamehow do i shrink a image in pygamepygame rotate memorypygame rotate image around pivotrezise object pygamepygame how to change a pictures sizehow to change the dimesions of an image pygamepygame scale an image downhow to resize an image pygamechange the resolution of a picture in pygamepygame changingsize of imagepygame image load widthscale img pygamepygame size of imagepygame size imagehow to make pygame tranform scale betterhow to change the size of an image in pygamepytgame transform rotate 28 29pygame png sizechange image sixe pygamepygame get size of imaherotate an image pygamep 5bygame resize imagehow to upscale an image pygamepygame increase image sizehow to get display size in pygamerotating image pygamepygame scale an imagepygame transform rotatehow to size up images in pygamepygame image set sizepygame make an image rotate over a pointchange dimensions of a foto pygamehow to shrink image pygamehow to resize image with pygamepython pygame rotate functionscreen blit sizephoto size in pygame 5d 5crotate a surface pygmaeresize image in pygamepygame image rotatepygame size of iresizing images in pygameset rotation of image in pygamechange size image python pygamehow to resize an image in python using pygamehow to size an image pygamepygame change the size of imagehow to reduce the dimensions of an image in pygamesize in pygamepygame change surface sizepygame image wont scalepygame image render sizepygame how to resize an image to fullscreenrotate images in pygamepygame set image sizescale down image pygametransform image pygamehow to resize an image in pygame without losing qualityhow to get dimensions of image in pygamepygame set image rotationrotate image from center pygamepygame shrink imagepygame background image full screenhow to scale a image in pygamehow to scale down pygame imagechange the image size in pygamecustomize the width of an image pygamepygame scale up imagepygame transform flippygame load image sizescaling a pygame imagehow to change the size of picture in pygame 5chow to rotate image in pygameblit an image pygame at double sizepygame change size of imagepygame resizepygame image scalescaling images in pgamerotate image python pygamepygame transform rotate 28 29pygame image transformpygame transform scale 28pygame image load 28 29 29how to transform scale in pygamepygame transform fliphow to change a size of an image in pygameptgame rotate imageresize pygame imageresize pygame load imageimage pygame transform positionpygame rotate image 5chow to resize and display an image in pygamehow to load images with pygame with scalepygame scale image 2xhow to strech image size in pygamehow to resize an image to smaller in pygamescale an image down pygamehow to rotate a image to mouse in pygamepython pygame how to scale an objectauto scale to display size pygamescale images to window size pygamescale pygame surfacehow to resize imag ein pygameimage scale pygamerotater img pygamehow to make an image rotate in pygamehow to stretch a image in pygamehow to change the size of an image pygameshrink image pygamepygame make image biggerhow to change the size od an image in pygame pythonpygasme scalepygame load image at scalerotate rect pygamehow do i shrink a image in pygame in pythonpygame make an image rotate around a pointpygame load image resizepygame create bigger image then screenpygame changing size of imagehow to shrink an image pygamehow to resize image pygameresize images in pygamepygame alter image sizepygame transform scale 28 29pygame image dimensionsresize surface pygamehow to scale an image pygamehow to define size of image in pygamepygame make image the right sizepygame get image scalehow to rotate an image pygameresize and imagepygametranformation image in pygamepygame scale imagehow to rotate img in pygame horizontalyhow to change capacity of image in pygamerotate pygameset size of image in pygameget size of pygame displaypygame resize an imagepygame transform flip vs rotatehow to change a images size in pygamehow to scale image pygamepygame image sizrpygame transform scale 28pygame image load pygame latest versionpygame change image based on pixel sizepygame transform scale examplepygame scale recthow to scale an image by 2 in pygamerotate image crashing pygamepygame transformhow to rotate a picture in pygamehow to get image size in pygamepygame scale all imagesmake image smaller pygamepython pygame how to add a scalescale image to window pygametransform image scale pygamerescalse image pygamepygame draw image with set sizepygame scale image downpygame zoompygame rotate image centerchange size of image pygamepygame image rotatehow to change the size of images pygamehow to resize image in pygameget dimensions of image pygamehow to rotate an image around it center in pygamehow to rotate an image with pygamehow to make an image bigger in pygamepygame image scalingpygame how to upscale imgaepygame get image widthscaling pygame imagehow to change size of image in pygamepygame image stretchhow to shrink a picture pygamerotate image pygaempygame transform scale 28pygame image loadpygame how img chage sizepygame resize imapygame function that rotate an imagesmooth transformation pygamepygame scale down imagehow to increase the size of the image in pygamescaling images pygamepygame image load with sizepygame how to increase image sizehow to change the size of a pygame window with imageshow to rotate picture in pygamechange the size of an image pygamepygame image shrink to sizehow to rotate image pygamehow to rotate image through mouse in pygamepygame get width of imageupscale images pygamepygame resize pictureimage width pygamepygame get image sizehow to scale in pygamepygame transform laplacian 28 29resize an image pygamepygame load and scalehow to scale image in pygamehow to rotate a sprite pygamehow to set image size in pygamepygame get size of scaled imagescale image in pygamehow to set image size in python in pygamepygame scale image to fit rectanglehow to shrink image size pygamescale an image up pygamepygame rotate image around pointpygame upscale imagepygame image transform scalepygame image resizepygame how to resize an imagepygame transform scale 28 29pygame flip imagehow to rotate image to a angle in pygamescaling image in pygameresizing image pygamepygame image widthblit rotate pygamepygame how to change scalechange image size pygamepygame size of a scaled imagehow to scale and rotate image in pygamepygame scale surfacescale pygameresizing images pygamepygame transformpygame crop imagepygame transform rotatehow to resize a image pygamehow to rotate images in pygame on an axispygame rotate transformrotate image pygamepygame draw blit image smallerhiw ti resize image in pytgamehow to make a cimage grow then shrink in pygamechange image size in pygameresize image pygamehow to scale images pygamemake picture bigger pygamehow to upscale image pygamepython pygame display image biggerrescale image pygamemake image bigger pygamerisizable image in pygamepygame dimensions of imagebetter pygame transform scalepygame change image sizehow to alter image size pygame blitpygame rotatehow to scalle up an image i npygamehow to change the scale in pygame of an imgagepygame scale percentagepython pygame resize imagehow to resize imgs in pygameget image size pygamepygame blit image smallerhow to rotate a image about a point in pygamepygame image resolutionhow to rotate an image in pygamehow to make image smaller pygamepygame scale image size how to change a picture position in pygamepygame scale imagespython pygame how to change the size of an imageimage size pygametransform image on load pygamehow make an image smaller in pygamepygame reduce image sizehow to decrease the image size in pygamehow to resize an image in pygameshould resized images be converted pygamehow to print image size in pygamepygame transform scale 2xhow can i render jpeg images in pygameresize img pygamehow to scale an image in pygamemaking an image smaller pygamehow to shrink an image in pygamerotate in pygamepygame transform rotate objectresize loaded image pygamehow to change image size in pygamepygame image rotate centerimage size adjust on pygamepygame resize imageresize a picture pygamehow to scale screen size to image in pygamehow to reduce the scale of an image python pygameset dimensions of image pygametransform pygamepygame rotatinghow to rotate img in pygamepygame image rotationpygame rotate a drawn rectreduce the image size in pygamecan you change the size of an image in pygamepygame scaling not working on full imagepygame change angle of imageset rotation of image pygamepygame set rotation of imagehow to rotate from centre of image pygamepygame how to scale imagepygame change resolution of imagempygame scale imagepygame make smallerchange size of image in pygamehow to change the size of image in pygamehow to increase the size of image in pygamepygame pixel sizepygame transform rotozoomtransform scale pygamedraw image bigger pygamehow to decrease size of an image in pygamerotate photo in pygamehow to modify screen size to picture pygamescale tranformation image in pygamepygame trasnform scalescale pygame imagecan i set the width and the height of an image in pygamepygame how to resize imagerotation image pygamepgygame resize imagetransform rotate pygamescale image to be smaller in pygamepygame change imagepygame how do i scale an image by 1 5how to rotate an image using rect and vector in pygamehow to change the size of a image python pygamepygame scale image