Pillow thumbnail 图片缩放
【摘要】 所属的课程名称及链接[AI基础课程--常用框架工具]环境信息* ModelArts * Notebook - Multi-Engine 2.0 (python3) * JupyterLab - Notebook - Conda-python3 * Pillow 5.0.0Pillow thumbnail 图片缩放%matplotlib inlinefrom PIL impo...
所属的课程名称及链接
环境信息
- * ModelArts
- * Notebook - Multi-Engine 2.0 (python3)
- * JupyterLab - Notebook - Conda-python3
- * Pillow 5.0.0
- * JupyterLab - Notebook - Conda-python3
- * Notebook - Multi-Engine 2.0 (python3)
Pillow thumbnail 图片缩放
%matplotlib inline
from PIL import Image
import matplotlib.pyplot as plt
img = Image.open('image.png')
w,h = img.size
plt.imshow(img)
<matplotlib.image.AxesImage at 0x7f4631ad0710>
# 参数是元组
img.thumbnail((w/2,h/2))
plt.imshow(img)
<matplotlib.image.AxesImage at 0x7f46200758d0>
help
help(img.thumbnail)
Help on method thumbnail in module PIL.Image:
thumbnail(size, resample=3) method of PIL.PngImagePlugin.PngImageFile instance
Make this image into a thumbnail. This method modifies the
image to contain a thumbnail version of itself, no larger than
the given size. This method calculates an appropriate thumbnail
size to preserve the aspect of the image, calls the
:py:meth:`~PIL.Image.Image.draft` method to configure the file reader
(where applicable), and finally resizes the image.
Note that this function modifies the :py:class:`~PIL.Image.Image`
object in place. If you need to use the full resolution image as well,
apply this method to a :py:meth:`~PIL.Image.Image.copy` of the original
image.
:param size: Requested size.
:param resample: Optional resampling filter. This can be one
of :py:attr:`PIL.Image.NEAREST`, :py:attr:`PIL.Image.BILINEAR`,
:py:attr:`PIL.Image.BICUBIC`, or :py:attr:`PIL.Image.LANCZOS`.
If omitted, it defaults to :py:attr:`PIL.Image.BICUBIC`.
(was :py:attr:`PIL.Image.NEAREST` prior to version 2.5.0)
:returns: None
备注
1. 感谢老师的教学与课件
2. 欢迎各位同学一起来交流学习心得^_^
3. 沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。
2. 欢迎各位同学一起来交流学习心得^_^
3. 沙箱实验、认证、论坛和直播,其中包含了许多优质的内容,推荐了解与学习。
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)