mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 10:16:17 +03:00
Fixed palette issue when saving
This commit is contained in:
parent
b8ff91ab3b
commit
88fca0f555
|
@ -301,14 +301,17 @@ RAWMODE = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def _convert_mode(im):
|
def _convert_mode(im, initial_call=False):
|
||||||
# convert on the fly (EXPERIMENTAL -- I'm not sure PIL
|
# convert on the fly (EXPERIMENTAL -- I'm not sure PIL
|
||||||
# should automatically convert images on save...)
|
# should automatically convert images on save...)
|
||||||
if Image.getmodebase(im.mode) == "RGB":
|
if Image.getmodebase(im.mode) == "RGB":
|
||||||
|
if initial_call:
|
||||||
palette_size = 256
|
palette_size = 256
|
||||||
if im.palette:
|
if im.palette:
|
||||||
palette_size = len(im.palette.getdata()[1]) // 3
|
palette_size = len(im.palette.getdata()[1]) // 3
|
||||||
return im.convert("P", palette=1, colors=palette_size)
|
return im.convert("P", palette=1, colors=palette_size)
|
||||||
|
else:
|
||||||
|
return im.convert("P")
|
||||||
return im.convert("L")
|
return im.convert("L")
|
||||||
|
|
||||||
|
|
||||||
|
@ -330,7 +333,7 @@ def _save(im, fp, filename, save_all=False):
|
||||||
if im.mode in RAWMODE:
|
if im.mode in RAWMODE:
|
||||||
im_out = im.copy()
|
im_out = im.copy()
|
||||||
else:
|
else:
|
||||||
im_out = _convert_mode(im)
|
im_out = _convert_mode(im, True)
|
||||||
|
|
||||||
# header
|
# header
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user