“Python Pil Invert Bildfarbe” Code-Antworten

Python Pil Invert Bildfarbe

from PIL import Image
import PIL.ImageOps    

image = Image.open('your_image.png')

inverted_image = PIL.ImageOps.invert(image)

inverted_image.save('new_name.png')
Cute Caribou

Python Pil Invert Bildfarbe

#If the image is RGBA transparent this will fail... This should work though:

from PIL import Image
import PIL.ImageOps    

image = Image.open('your_image.png')
if image.mode == 'RGBA':
    r,g,b,a = image.split()
    rgb_image = Image.merge('RGB', (r,g,b))

    inverted_image = PIL.ImageOps.invert(rgb_image)

    r2,g2,b2 = inverted_image.split()

    final_transparent_image = Image.merge('RGBA', (r2,g2,b2,a))

    final_transparent_image.save('new_file.png')

else:
    inverted_image = PIL.ImageOps.invert(image)
    inverted_image.save('new_name.png')
Cute Caribou

Ähnliche Antworten wie “Python Pil Invert Bildfarbe”

Fragen ähnlich wie “Python Pil Invert Bildfarbe”

Weitere verwandte Antworten zu “Python Pil Invert Bildfarbe” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen