修改照片分辨率,宽高的比例不变

import Image

def change_resolution(picPath, reslution):
    img = Image.open(picPath)
    x, y = img.size
    print x,y
    changex = float(x)/reslution[0]
    changey = float(y)/reslution[1]
    
    if changex > 1 or changey >1:
        change = changex if changex > changey else changey         
        final_fenbianlv =  (int(x / change), int(y / change))
        print final_fenbianlv
        img.resize(final_fenbianlv).save('result.jpg')
        
if __name__ == '__main__':
    change_resolution('pictest.jpg',(1136, 640))

已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页