There are often daily website called for the resolution of the image upload, every time I see online tutorial is by means of ps, Mito Xiu Xiu toss. Feeling too toss. With python to write a little code conversion accuracy to meet the daily needs.
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))
The following are the comparison of before and after pictures of the conversion.