(1)对图片生成缩略图
1 from PIL import Image 2 im = Image.open("C:\Users\litchi\Desktop\picture1.jpg") 3 im.thumbnail((128, 128)) 4 im.save("pictureTN","JPEG")
图片对比:
(2)
图像颜色交换
1 from PIL import Image 2 im = Image.open("C:\Users\litchi\Desktop\picture1.jpg") 3 r, g, b = im.split() 4 om = Image.merge("RGB", (b, g, r)) 5 om.save(‘picture1BGR.jpg‘)
(3)提取图片轮廓
1 from PIL import Image 2 from PIL import ImageFilter 3 im = Image.open("C:\Users\litchi\Desktop\picture1.jpg") 4 om = im.filter(ImageFilter.CONTOUR) 5 om.save(‘picture1Contour.jpg‘)
(4)图片浮雕处理
1 from PIL import Image 2 from PIL import ImageFilter 3 im = Image.open("C:\Users\litchi\Desktop\picture2.jpg") 4 om = im.filter(ImageFilter.EMBOSS) 5 om.save(‘picture2EMBOSS.jpg‘)
(4)提取GIF图像每一帧
1 from PIL import Image 2 im = Image.open("C:\Users\litchi\Desktop\picture3.gif") 3 try: 4 im.save(‘picframe{:02d}.png‘.format(im.tell())) 5 while True: 6 im.seek(im.tell()+1) 7 im.save(‘picframe{:02d}.png‘.format(im.tell())) 8 except: 9 print("处理结束")
(3)图片的锐化处理
from PIL import Image from PIL import ImageEnhance im = Image.open("C:\Users\litchi\Desktop\picture2.jpg") om = ImageEnhance.Sharpness(im) om.enhance(20).save(‘picture2EnContrast.jpg‘)
原文:https://www.cnblogs.com/litchi666/p/12748038.html