#Code for a 4×4 binary B/W image
#code for a 4x4 binary B/W image
from PIL import Image
width=4
height=4
img = Image.new('1', (width, height))
list_of_pixels = list(img.getdata())
list_of_pixels= [
0, 0, 0, 1,
0, 1, 1, 1,
0, 0, 1, 1,
0, 1, 1, 1]
print list_of_pixels
img.putdata(list_of_pixels)
img.show()
img.save('myimage.png')
#Code for creating a 16×16 color favicon image
#Code for creating a 16x16 color favicon image using randomly generated colors
from PIL import Image
from random import randint
width=16
height=16
img = Image.new('RGB', (width, height))
pixels = list(img.getdata())
for row in range(16):
for col in range(16):
pixels[row*16 +col] = (randint(0,255),randint(0,255),randint(0,255))
print pixels
img.putdata(pixels)
img.show()
img.save('myimage.png')
#Code for creating a 256×256 color gradient
#Code for creating a color gradient
from PIL import Image
width=256
height=256
img = Image.new('RGB', (width, height))
pixels = list(img.getdata())
for row in range(height):
for col in range(width):
pixels[row*height +col] = (255,row,col)
print pixels
img.putdata(pixels)
img.show()
img.save('myimage.png')
Like this:
Like Loading...
Discussion
No comments yet.