Muitas vezes há website diária chamada para a resolução do envio de imagens, cada vez que vejo tutorial online é por meio de ps, Mito Xiu Xiu atirar. Sentindo muito atirar. Com python para escrever uma precisão pouco de conversão de código para atender às necessidades diárias.
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))
A seguir estão a comparação de fotos antes e depois da conversão.