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
标签:PIL,python,image,height,width,Resampling,reducing,Image,resize From: https://www.cnblogs.com/chucklu/p/16943266.html