I'm trying to add a new method to the Image class from Python Imaging Library. I want to have a new class called DilateImage which acts exactly as the original Image class, except it also includes a dilate() function which modifies the class instance when it is executed on one. Here's my example code (that isn't working):
import Image
def DilateImage(Image):
def dilate(self):
imnew = self.copy()
sourcepix = imnew.load()
destpix = self.load()
for y in range(self.size[1]):
for x in range(self.size[0]):
brightest = 255
for dy in range(-1,2):
for dx in range(-1,2):
try:
brightest = min(sourcepix[x+dx,y+dy], brightest)
except IndexError:
pass
destpix[x, y] = brightest
When I try to use this new class type to create an instance that uses the base class' "open" function it fails:
>>> test = DilateImage.open("test.jpg")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'function' object has no attribute 'open'