mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-04-27 20:43:43 +03:00
Merge pull request #180 from d-schmidt/master
create a palette before converting transparent L-mode to RGBA
This commit is contained in:
commit
1aacded655
10
PIL/Image.py
10
PIL/Image.py
|
@ -713,6 +713,16 @@ class Image:
|
||||||
if dither is None:
|
if dither is None:
|
||||||
dither = FLOYDSTEINBERG
|
dither = FLOYDSTEINBERG
|
||||||
|
|
||||||
|
# fake a P-mode image, otherwise the transparency will get lost as there is
|
||||||
|
# currently no other way to convert transparency into an RGBA image
|
||||||
|
if self.mode == "L" and mode == "RGBA" and "transparency" in self.info:
|
||||||
|
from PIL import ImagePalette
|
||||||
|
self.mode = "P"
|
||||||
|
bytePalette = bytes([i//3 for i in range(768)])
|
||||||
|
self.palette = ImagePalette.raw("RGB", bytePalette)
|
||||||
|
self.palette.dirty = 1
|
||||||
|
self.load()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
im = self.im.convert(mode, dither)
|
im = self.im.convert(mode, dither)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user