画像アップロードの解決のために呼ばれる毎日のウェブサイトは頻繁にありますが、私はオンラインチュートリアルを見るたびは、ps、水戸秀秀投げによるものです。あまりにも投げる感じ。毎日のニーズを満たすために少しのコード変換精度を書くためのpythonを持ちます。
from PIL 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
#print( change)
#print( int(reslution[0] / change), int(reslution[1] / change))
print('output reslution:')
print( int(x / change), int(y / change))
img.resize((int(x / change), int(y / change))).save('result.jpg')
if __name__ == '__main__':
change_resolution('20190123154207.jpg', (1136, 640))
以下は、前と変換後の画像を比較しています。