Skip to content

Inverting PNG Files #7473

Answered by radarhere
Yodazon asked this question in Q&A
Oct 17, 2023 · 1 comments · 11 replies
Discussion options

You must be logged in to vote

The error is being raised on ImageOps.invert(img), which is not in the "RGBA" part of my code - this makes me think that I've solved your RGBA problem, but there is another mode you are having trouble with as well.

Does this code print out something like "Image mode: RGBA" just before the traceback? What is that mode?

def invertImage(imgs):
    converted = []
    for img in imgs:
        if img.mode == "RGBA":
            img_a = img.getchannel("A")
            img_rgb = img.convert("RGB")
            invert = ImageOps.invert(img_rgb)
            invert.putalpha(img_a)
        else:
            try:
                invert = ImageOps.invert(img)
            except OSError as e:
           …

Replies: 1 comment 11 replies

Comment options

You must be logged in to vote
11 replies
@Yodazon
Comment options

@radarhere
Comment options

@Yodazon
Comment options

@radarhere
Comment options

Answer selected by Yodazon
@radarhere
Comment options

@Yodazon
Comment options

@radarhere
Comment options

@Yodazon
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants