hanzgs
hanzgs

Reputation: 1616

How to set image size to display in Ipython.display?

How to set the image size to display? Running in VSCode Jupyter Interactive Window

from PIL import Image
from IPython.display import display
display(Image.open('imageURL'))

This code displays the Image as it is, i.e showing the original size,

Tried this, which works, but how to keep the ratio, image shrunks as it is

image = Image.open('imageURL')
image = image.resize((500,500),Image.ANTIALIAS)
display(image)

Upvotes: 8

Views: 15965

Answers (3)

Keiku
Keiku

Reputation: 8803

If you are dealing with video, you can do the following:

from IPython.display import display, Video
display(Video(data=video_path, embed=True, width = 600, height = 300))

Note: It is not an answer to the image, but it is described as a reference.

Upvotes: 0

DocOc
DocOc

Reputation: 755

Try

from IPython.display import Image, display
display(Image('image.png', width=600))

You can also set a height.

Upvotes: 10

Arif
Arif

Reputation: 674

Try this code

image = Image.open("imageURL")
scale = 0.3
display(image.resize(( int(image.width * scale), int(image.height * scale))))

Upvotes: 2

Related Questions