您的位置:首页 > 编程语言 > Python开发

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

2017-07-11 15:06 417 查看
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)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐