>>> import Image
Les fonctions suivantes retournent un objet de la classe Image :
>>> dd=open('lenna256.png') # dd est un objet de type file
>>> import Image as im
>>> tt=im.open(dd)
>>> dd2=im.open('lenna256.png')
>>> import Image as im
>>> dd = im.new('RGB',(32,43),'cyan')
où p1 est le pixel correspondant de l'image i1, et p2 celui de i2.
>>> import Image as im
>>> i1 = im.open('image1.png')
>>> i2 = im.open('image2.jpg')
>>> print i1.size, i2.size
(256, 256) (256, 256)
>>> retour = im.blend(i1, i2, 0.3)
>>> retour.show()
Chaque pixel de la sortie a pour valeur (p1 x (1 - m) + p2 x m) où p1, p2 et m sont les pixels correspondant dans i1, i2 et mask.
>>> import Image as im
>>> i1 = im.open('image1.png')
>>> i2 = im.open('image2.png')
>>> print i1.size, i2.size
(104, 85) (64, 64)
>>> i1 = i1.resize((64,64))
>>> print i1.size, i2.size
(64, 64) (64, 64)
>>> masque = im.new('1',(64,64)) # Masque tout noir
>>> masque.paste('white',(20,20,40,40)) # On colle un carré blanc
>>> masque.show()
>>> retour = im.composite(i1,i2,masque)
>>> retour.show()
>>> def f(x): return x+1
>>> import Image as im
>>> image=im.open('chaos.png')
>>> retour = im.eval(image,f)
>>> retour.show()
>>> import Image as im
>>> im1 = im.open('chaos.png')
>>> im2 = im.open('lifc.png')
>>> im3 = im.open('aze.png')
>>> print im1.size, im2.size, im3.size
(64, 64) (104, 85) (64, 64)
>>> im2 = im2.resize((64,64))
>>> image = im.merge('RGB',[im1, im2, im3])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/PIL/Image.py", line 1998, in merge
raise ValueError("mode mismatch")
ValueError: mode mismatch
>>> print im1.mode, im2.mode, im3.mode
P P P
>>> im1 = im1.convert('L')
>>> im2 = im2.convert('L')
>>> im3 = im3.convert('L')
>>> image = im.merge("RGB",[im1, im2, im3])
>>> image.show()