Skip to content
New issue

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

add width, height support to put_image_data #304

Open
orena1 opened this issue Nov 28, 2022 · 1 comment
Open

add width, height support to put_image_data #304

orena1 opened this issue Nov 28, 2022 · 1 comment

Comments

@orena1
Copy link

orena1 commented Nov 28, 2022

Hi,
As far as I can see, there is no way to scale an image when using put_image_data.
e.g.:

from ipycanvas import Canvas
import numpy as np
canvas = Canvas(width=300, height=300)
canvas.put_image_data(np.random.uniform(size=(200,200,3)))
canvas

image

No matter the width and height of the canvas... Which is different from draw_image where there are two other variables (width, height) which scale the image, is it possible to add this feature?

@martinRenou martinRenou added enhancement New feature or request and removed enhancement New feature or request labels Nov 29, 2022
@martinRenou
Copy link
Collaborator

ipycanvas tries to stay close to the web canvas API, and this is not a feature that this API provides: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/putImageData

Though you can actually work around this by having another Canvas:

from ipycanvas import Canvas
import numpy as np

canvas1 = Canvas(width=200, height=200)
canvas1.put_image_data(np.random.uniform(size=(200,200,3)))

canvas2 = Canvas(width=300, height=300)
# Draw canvas1 on canvas2 and scale it down to (100, 100)
canvas2.draw_image(canvas1, 0, 0, 100, 100)

canvas2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants