PIL은 현재 PNG8의 전체 알파를 지원하지 않는 것 같습니다. 당신이 나쁜 느낌이있어 경우 http://mail.python.org/pipermail/image-sig/2010-October/006533.html
, 당신은 monkeypatch 수 PIL :
from PIL import Image, ImageFile, PngImagePlugin
def patched_chunk_tRNS(self, pos, len):
i16 = PngImagePlugin.i16
s = ImageFile._safe_read(self.fp, len)
if self.im_mode == "P":
self.im_info["transparency"] = map(ord, s)
elif self.im_mode == "L":
self.im_info["transparency"] = i16(s)
elif self.im_mode == "RGB":
self.im_info["transparency"] = i16(s), i16(s[2:]), i16(s[4:])
return s
PngImagePlugin.PngStream.chunk_tRNS = patched_chunk_tRNS
def patched_load(self):
if self.im and self.palette and self.palette.dirty:
apply(self.im.putpalette, self.palette.getdata())
self.palette.dirty = 0
self.palette.rawmode = None
try:
trans = self.info["transparency"]
except KeyError:
self.palette.mode = "RGB"
else:
try:
for i, a in enumerate(trans):
self.im.putpalettealpha(i, a)
except TypeError:
self.im.putpalettealpha(trans, 0)
self.palette.mode = "RGBA"
if self.im:
return self.im.pixel_access(self.readonly)
Image.Image.load = patched_load
Image.open('kHrY6.png').convert('RGBA').save('kHrY6-out.png')
출처
2010-11-20 11:14:59
adw
@Kyle :
패치가 읽기 전용 지원을 위해 여기에 있습니다 당신은 게시 할 것'input.png' 및 'output.png'? 문제를 재현 할 수없는 것 같습니다. – unutbu
파일을 편집하여 민감한 내용을 "수정"하고 다시 저장된 이미지가 정상적으로 작동합니다. 그래서 나는 input.png이 8 비트 PNG이고, 웹 그래픽 외부에서는 매우 드물다는 것을 고려하여 너무 많은 노력을 고려해야한다고 생각합니다. –
'.png' 형식의 맛은'input.png'입니다 - 어떤 형식으로 시작해야할까요? – martineau