python中图片处理之调整图片大小

xiaoxiao2021-02-28  63

from PIL import Image import os ImageNames=os.listdir('E:\\digger\\diggerdatabase') for i in range(len(ImageNames)):     infile = 'E:\\digger\\diggerdatabase\\'+str(i+1)+'.jpg'  #输入图片所在路径     outfile ='E:\\digger\\diggerdatabase\\'+str(i+1)+'.jpg' #输出图片所在路径     Image.open(infile).convert('RGB').save(outfile) # convert the image to RGB mode  very important 将图片转化为RGB模式,虽然我不知道为什么,但是没有这一步会报错     im = Image.open(infile)      (x, y) = im.size  # read image size     x_s = 250  # define standard width     y_s = 250  # calc height based on standard width     out = im.resize((x_s, y_s), Image.ANTIALIAS)  # resize image with high-quality     out.save(outfile)     print(str(i+1)+'original size: ', x, y)     print(str(i+1)+'adjust size: ', x_s, y_s)
转载请注明原文地址: https://www.6miu.com/read-66034.html

最新回复(0)