We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rendering the image normally without attempting to resize, with image(img, 10,20) I get this:
image(img, 10,20)
However when trying to dynamically resize the width to half its size I get the image below
from p5 import * from components.shuffler import Shuffler from components.debugger import Debugger from game_logic.constants import ITEMS # Intellisense can't find these on its own for some reason global mouse_is_pressed, mouse_x, mouse_y global shuffler, debugger global width, height SHUFFLED_ITEMS = list(ITEMS.keys()) img = None img_width = None img_height = None def start(): """ Start the UI. This function takes over the main thread (never returns)! """ run(renderer="skia", sketch_draw=draw, sketch_setup=setup) def setup(): size(1024, 600) #touchscreen size background(200) global shuffler, debugger, img, img_width, img_height shuffler = Shuffler() debugger = Debugger() img = loadImage("kart_ui/images/no-item.png") print("original size", img.width(), img.height()) img_width = int(img.width()/2) img_height = int(img.height()/2) # no_tint() def draw(): background(255) fill(255) # print(type(img)) # print(img_width, img_height) image(img, 10,20, img_width, img_height) def mouse_pressed(): if mouse_x < width/2: shuffler.shuffle(SHUFFLED_ITEMS[int(random_uniform(0, len(SHUFFLED_ITEMS)))]) else: shuffler.use_item() if __name__ == "__main__": start()
The text was updated successfully, but these errors were encountered:
Hi,
Looking at the lib source code, image() doesn't appear to do a resize. Although the docs suggest it should if you give image() a width and height
Until that is fixed or clarified as to what the behaviour should be, this ugly bit of code will work without editing the library,
from p5 import * import skia from p5.sketch.Skia2DRenderer.image import SkiaPImage pimg1 = None pimg2 = None w = None h = None def setup(): size(1024, 600) background(200) global pimg1, pimg2, w, h simg = skia.Image.open("lena.png") w = simg.width() h = simg.height() simg_scaled = simg.resize(int(w/2), int(h/2)) pimg1 = SkiaPImage(w, h, pixels=simg.toarray()) pimg2 = SkiaPImage(int(w/2),int(h/2), pixels=simg_scaled.toarray()) def draw(): background(255) fill(255) image(pimg1, 0, 0) image(pimg2, w, 0) image(pimg2, w, int(h/2)) if __name__ == "__main__": run(renderer="skia")
Loading the image via skia directly and using skia to resize. Then converting the resized image from a skia image to a PImage.
#The loading via skia and converting to a PImage is also what loadImage() does.
resize.zip
Sorry, something went wrong.
No branches or pull requests
Rendering the image normally without attempting to resize, with
image(img, 10,20)
I get this:
However when trying to dynamically resize the width to half its size I get the image below
The text was updated successfully, but these errors were encountered: