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-09-10
  • 2021-11-27
  • 2021-11-25
  • 2021-10-19
  • 2021-12-31
  • 2021-04-16
  • 2021-08-23
  • 2021-08-17
猜你喜欢
  • 2021-04-04
  • 2021-08-17
  • 2021-12-19
  • 2021-04-17
  • 2021-10-15
  • 2021-12-18
  • 2021-06-26
  • 2021-09-14
相关资源
相似解决方案