首页 > 编程语言 > 详细

使用python进行图像处理-调整图片大小

时间:2014-12-07 16:23:36      阅读:3741      评论:0      收藏:0      [点我收藏+]

python有一个图像处理库——PIL,可以处理图像文件。PIL提供了功能丰富的方法,比如格式转换、旋转、裁剪、改变尺寸、像素处理、图片合并等等等等,非常强大。

举个简单的例子,调整图片的大小:

import Image

infile = ‘D:\\original_img.jpg‘
outfile = ‘D:\\adjust_img.jpg‘
im = Image.open(infile)
(x,y) = im.size #read image size
x_s = 250 #define standard width
y_s = 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

‘‘‘
OUTPUT:
original size:  500 358
adjust size:  250 179
‘‘‘

 

使用python进行图像处理-调整图片大小

原文:http://www.cnblogs.com/chjbbs/p/4149452.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!