码迷,mamicode.com
首页 > 其他好文 > 详细

pil

时间:2015-12-06 00:01:53      阅读:285      评论:0      收藏:0      [点我收藏+]

标签:

http://effbot.org/imagingbook/

一、安装

pip install PIL --allow-external PIL --allow-unverified PIL
二、转为二色
 1 import Image
 2 img=Image.open(o.jpg)
 3 w,h=img.size
 4 img1=Image.new(RGB,(w,h))
 5 for x in range(w):
 6     for y in range(h):
 7         (r,g,b)=img.getpixel((x,y))
 8         if r+g+b>255:
 9             nc=(255,255,255)
10         else:
11             nc=(0,0,0)
12         img1.putpixel((x,y),nc)
13 img1.save(n.jpg)

转黑白
img.convert(‘1‘)

缩放

img.resize(...)

img.thumbnail((new_w, new_h))

旋转

img.rotate(angle)
滤镜

img1 = img.filter(ImageFilter.BLUR)

画图

1 import ImageDraw 
2 draw = ImageDraw.Draw(img) 
3 width,height = img.size 
4 draw.line(((0,0),(width-1,height-1)),fill=255) #画直线 
5 draw.line(((0,height-1),(width-1,0)),fill=255) 
6 draw.arc((0,0,width-1,height-1),0,360,fill=255) #画椭圆 
7 img.save(self.save_file) 

增强

 1 import ImageEnhance 
 2 brightness = ImageEnhance.Brightness(img) 
 3 bright_img = brightness.enhance(2.0) ##亮度增强 
 4 bright_img.save(img1) 
 5 sharpness = ImageEnhance.Sharpness(img) 
 6 sharp_img = sharpness.enhance(7.0) #锐度增强 
 7 sharp_img.save(img1) 
 8 contrast = ImageEnhance.Contrast(img) #对比度增强 
 9 contrast_img = contrast.enhance(2.0)  
10 contrast_img.save(img1) 

 

pil

标签:

原文地址:http://www.cnblogs.com/perel/p/5022542.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!