chjbbs

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
\'\'\'

 

posted on 2014-12-07 15:25  Chen Jian  阅读(50832)  评论(0编辑  收藏  举报

分类:

技术点:

相关文章:

  • 2021-12-19
  • 2021-08-17
  • 2021-10-15
  • 2021-04-17
  • 2021-03-01
  • 2021-12-18
猜你喜欢
  • 2021-09-29
  • 2021-08-13
  • 2022-02-07
  • 2022-02-14
  • 2021-10-16
  • 2021-04-04
相关资源
相似解决方案