pillowcases module
Library that makes it possible to work in a concise, algebraic way with Python Imaging Library image objects.
- class pillowcases.pillowcases.Image[source]
Bases:
PIL.Image.ImageDerived class for
PIL.Image.Imagethat is hashable. When thepillowcases.pillowcasesmodule is imported, thePIL.Image.Imageclass is redefined to refer to thepillowcases.pillowcases.Imageclass.>>> import pillowcases >>> i = PIL.Image.frombytes('RGBA', (2, 2), bytes([0]*16)) >>> isinstance(i, pillowcases.Image) True
Because instances of this derived class are hashable, they can be added as elements to
setobjects and can be used as keys indictobjects.>>> j = PIL.Image.frombytes('RGBA', (2, 2), bytes([0]*16)) >>> k = PIL.Image.frombytes('RGBA', (2, 2), bytes([255]*16)) >>> len({i, j, k}) 2 >>> d = {j: 1, k: 2} >>> d[k] 2
Compare the above to the default behavior of the
PIL.Image.Imageclass, demonstrated below.>>> from importlib import reload >>> PIL.Image = reload(PIL.Image) >>> i = PIL.Image.frombytes('RGBA', (2, 2), bytes([0]*16)) >>> j = PIL.Image.frombytes('RGBA', (2, 2), bytes([0]*16)) >>> j = PIL.Image.frombytes('RGBA', (2, 2), bytes([255]*16)) >>> len({i, j, k}) Traceback (most recent call last): ... TypeError: unhashable type: 'Image'