0

I'd like to apply some filters to an uploaded image. The filters get generated based on a text that gets entered by the user. This is how the function looks so far:

    def validate_email(self):
    textboxValue = self.lineEdit.text()
    image = self.open()
    for c in textboxValue:
        if c == 'a':
            image = image.filter(ImageFilter.GaussianBlur(1.05)).show()
        elif c == 'b':
            image = ImageEnhance.Brightness(image)
            image.enhance(1.1).show()
        elif c == 'c':
            image = ImageEnhance.Contrast(image)
            image = image.enhance(1.1).show()
        elif c == '@':
            image = ImageOps.grayscale(image).show()
        else:
            print(c)

I'm pretty sure that yesterday my code worked, but today I constantly get the error

AttributeError: object has no attribute ...

and the "..." differ, sometimes it's enhance, sometimes getbands etc. It's always the ImageEnhance part that causes the error. The GaussianBlur filter is working fine.. I read about that solution, but that didn't help me. I assume it's too old..

I'm new to Python so maybe I did some basic mistakes. I would be glad if somebody could help!

sonja
  • 924
  • 1
  • 21
  • 52

1 Answers1

1

The Image.show() method does not return an image.

Actually the gaussian blur filter has the same problem, but it starts with a fresh image.

Just separate the show method call and it should be fine.

def validate_email(self):
    textboxValue = self.lineEdit.text()
    image = self.open()
    for c in textboxValue:
        if c == 'a':
            image = image.filter(ImageFilter.GaussianBlur(1.05))
            image.show()
        elif c == 'b':
            e = ImageEnhance.Brightness(image)
            image = e.enhance(1.1)
            image.show()
        elif c == 'c':
            e = ImageEnhance.Contrast(image)
            image = e.enhance(1.1)
            image.show()
        elif c == '@':
            image = ImageOps.grayscale(image)
            image.show()
        else:
            print(c)
Roland Smith
  • 42,427
  • 3
  • 64
  • 94