python PIL resize
https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.resize
Image.resize(size, resample=None, box=None, reducing_gap=None)[source]
-
Returns a resized copy of this image.
- Parameters:
-
-
size – The requested size in pixels, as a 2-tuple: (width, height).
-
resample – An optional resampling filter. This can be one of
Resampling.NEAREST
,Resampling.BOX
,Resampling.BILINEAR
,Resampling.HAMMING
,Resampling.BICUBIC
orResampling.LANCZOS
. If the image has mode “1” or “P”, it is always set toResampling.NEAREST
. If the image mode specifies a number of bits, such as “I;16”, then the default filter isResampling.NEAREST
. Otherwise, the default filter isResampling.BICUBIC
. See: Filters. -
box – An optional 4-tuple of floats providing the source image region to be scaled. The values must be within (0, 0, width, height) rectangle. If omitted or None, the entire source is used.
-
reducing_gap – Apply optimization by resizing the image in two steps. First, reducing the image by integer times using
reduce()
. Second, resizing using regular resampling. The last step changes size no less than byreducing_gap
times.reducing_gap
may be None (no first step is performed) or should be greater than 1.0. The biggerreducing_gap
, the closer the result to the fair resampling. The smallerreducing_gap
, the faster resizing. Withreducing_gap
greater or equal to 3.0, the result is indistinguishable from fair resampling in most cases. The default value is None (no optimization).
-
- Returns:
-
An
Image
object.
This resizes the given image from (width, height)
to (width/2, height/2)
:
from PIL import Image
with Image.open("hopper.jpg") as im:
# Provide the target width and height of the image
(width, height) = (im.width // 2, im.height // 2)
im_resized = im.resize((width, height))
宽高分别resize为原来的0.9倍之后,图片从80KB,变成了600KB
作者:Chuck Lu GitHub |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
2021-12-02 2020年成人高考专升本高数(一)考试真题及答案 做题进度
2015-12-02 hierarchy中展开所有子项
2015-12-02 unity3d5.2.3中 调整视角
2015-12-02 NuGet在2015中的使用
2014-12-02 TeeChart.Direct2D.dll的使用