如何设置在 Ipython.display 中显示的图像大小?

han*_*zgs 6 python ipython

如何设置显示的图像尺寸?在 VSCode Jupyter 交互窗口中运行

from PIL import Image
from IPython.display import display
display(Image.open('imageURL'))
Run Code Online (Sandbox Code Playgroud)

此代码按原样显示图像,即显示原始大小,

尝试过这个,它有效,但是如何保持比例,图像按原样缩小

image = Image.open('imageURL')
image = image.resize((500,500),Image.ANTIALIAS)
display(image)
Run Code Online (Sandbox Code Playgroud)

Doc*_*cOc 5

尝试

from IPython.display import Image, display
display(Image('image.png', width=600))
Run Code Online (Sandbox Code Playgroud)

您还可以设置一个height.


小智 2

试试这个代码

image = Image.open("imageURL")
scale = 0.3
display(image.resize(( int(image.width * scale), int(image.height * scale))))
Run Code Online (Sandbox Code Playgroud)