# image.py - Let's make an image! # I downloaded Python Image Library (PIL) 1.1.6 # from pythonware.com # Documentation on it: # http://www.pythonware.com/library/pil/handbook/index.htm # When I installed it, the library of PIL files went in a new # directory inside C:\Python26 # page 479 of book tells us how to add something to search path. import sys # Add PIL to our search path if it's not already there. # To check, you can print sys.path - it's just a list. PIL_path = "C:\\Python26\\lib\\site-packages\\PIL" if PIL_path not in sys.path: sys.path.append(PIL_path) import Image # allows us to create image import ImageDraw # more fancy stuff # Basic image concepts are given in the "concepts" section of # the pythonware documentation. Also check out Image docs. # http://www.pythonware.com/library/pil/handbook/concepts.htm # http://www.pythonware.com/library/pil/handbook/image.htm # Note that these functions require us to use 'tuples' # which are like lists except they can't be changed. image = Image.new("RGB", (100,100)) # This will put a blue square in the middle: ##for x in range(40, 60): ## for y in range(40, 60): ## image.putpixel((x,y),(0,0,255)) # Vertical stripes for x in range(0,100): for y in range(0,100): if (x / 20) % 2 == 0: image.putpixel((x,y),(0,0,255)) else: image.putpixel((x,y),(255,0,0)) # output image.save("myimage.jpg")