a) 更改大小:Image.resize(size, filter) b) 显式将其转换为 JPEG(如果不是)并设置所需的质量。 c) 结合使用 a) 和 b)
无论您做什么,都需要在尺寸和质量之间进行权衡。
a) change the size: Image.resize(size, filter) b) explicitly convert it to JPEG (if it is not) and set the desired quality. c) use a combination of a) and b)
Whatever you do, there is a trade-off between size and quality.
这对我来说很有用,可以使用 For 循环使用 PIL 调整图像大小。变量 PRODUCTS 是一个包含所有产品名称的列表,但您也可以对文件中的每一行使用 readlines() 来执行此操作:
def resize_images(self):
products = PRODUCTS
for name in products:
try:
fp = open(filename + name + ".jpg", "rb")
img = Image.open(fp)
img.load()
img.save(filename + name + "_2" + ".jpg", quality=23)
fp.close()
except:
print name
This worked for me to use a For Loop to resize images using PIL. The variable PRODUCTS is a list that had all product names in it, but you can also use readlines() for each line in a file to do so:
def resize_images(self):
products = PRODUCTS
for name in products:
try:
fp = open(filename + name + ".jpg", "rb")
img = Image.open(fp)
img.load()
img.save(filename + name + "_2" + ".jpg", quality=23)
fp.close()
except:
print name
发布评论
评论(4)
如果图片格式是JPEG,这里有一个例子:
您需要阅读的参考文献是:
If the picture format is JPEG, here's an example:
The references you need to be reading are:
解决了。
我做到了....
Solved.
I did....
a) 更改大小:
Image.resize(size, filter)
b) 显式将其转换为 JPEG(如果不是)并设置所需的质量。 c) 结合使用 a) 和 b)无论您做什么,都需要在尺寸和质量之间进行权衡。
a) change the size:
Image.resize(size, filter)
b) explicitly convert it to JPEG (if it is not) and set the desired quality. c) use a combination of a) and b)Whatever you do, there is a trade-off between size and quality.
这对我来说很有用,可以使用 For 循环使用 PIL 调整图像大小。变量 PRODUCTS 是一个包含所有产品名称的列表,但您也可以对文件中的每一行使用 readlines() 来执行此操作:
This worked for me to use a For Loop to resize images using PIL. The variable PRODUCTS is a list that had all product names in it, but you can also use readlines() for each line in a file to do so: