凯哥英语视频
使用Python调整图片尺寸(大小)
python有一个图像处理库——PIL,可以处理图像文件。PIL提供了功能丰富的方法,比如格式转换、旋转、裁剪、改变尺寸、像素处理、图片合并等等等等,非常强大。
未知名网友让我给他的图片从98k改为20k以下,本想找个app搞定的,结果要收费,一怒之下找资料写代码。。。。。。Python,无所不能
import PIL.Image as Image
infile = 'images/001.jpg'
outfile = 'images/002.jpg'
im = Image.open(infile)
(x, y) = im.size # read image size
x_s = 250 # define standard width
y_s = int(y * x_s / x) # calc height based on standard width
out = im.resize((x_s, y_s), Image.ANTIALIAS) # resize image with high-quality
out.save(outfile)
print('original size: ', x, y)
print('adjust size: ', x_s, y_s)
别的也没啥说的
ok,那就这样吧~
欢迎各位大佬留言吐槽,也可以深入交流~