RGB值转GIF
# coding=UTF-8
from PIL import Image
x = 1280 #x坐标 将RGB值的行数进行因式分解,得到x,y的值
y = 960 #y坐标
imge = Image.new("RGB",(x,y)) #创建图片
file = open('D:\\ichunqiu\\item\\momo.txt') #打开RGB值的文件
for i in range(0,x): #遍历
for j in range(0,y):
line = file.readline() #获取一行RGB的值
rgb = line.split(",") #以逗号来分割RGB
imge.putpixel((i,j),(int(rgb[0]),int(rgb[1]),int(rgb[2])))
imge.show()
imge.save("D:\\ichunqiu\\item\\momo.gif","GIF")
变换图片尺寸
#coding = utf-8
>>> import Image
>>> img = Image.open("test.jpg")
>>> x,y = img.size
>>> img.thumbnail((x//2,y//2)) #缩小百分之50
>>> img.save('test.jpg','jpeg') #以jpeg保存
提取RGB值
#coding = utf-8
from PIL import Image
img = Image.open('test.jpg')
pix = img.load()
w = img.size[0]
h = img.size[1]
for x in range(w):
for y in range(h):
r, g, b = pix[x, y]