2006年07月15日 星期六 00:06
先把背景填成红色,再在图上贴一个有透明部分的png图,希望把透明效果实现出来(就是把后面的红色透出来):
im = Image.new('RGBA',(100,100),color=(255,255,255))
draw = ImageDraw.Draw(im)
draw.rectangle((0,0,100,100),fill="#cc0000")
i = Image.open('test.png')
im.paste(i,(0,0))
del draw
im.save('done.png')
但最后得到的done.png,贴上去的部分有透明,但不是把背景的红色透出来,而是把先前的红色给去掉了。
问题出在什么地方?
2006年07月15日 星期六 02:36
On 7/15/06, chen arthur <agakong at gmail.com> wrote: > > 先把背景填成红色,再在图上贴一个有透明部分的png图,希望把透明效果实现出来(就是把后面的红色透出来): > > im = Image.new('RGBA',(100,100),color=(255,255,255)) > draw = ImageDraw.Draw(im) > draw.rectangle((0,0,100,100),fill="#cc0000") > i = Image.open('test.png') > im.paste(i,(0,0)) im.paste(i,i) #等价于im.paste(i,None,i) 第一个参数image中只使用了其颜色信息,透明度的信息是通过第三个参数mask传进去的。 这里的确有一点不太直观,我第一次也弄糊涂了。 del draw > im.save('done.png') > > 但最后得到的done.png,贴上去的部分有透明,但不是把背景的红色透出来,而是把先前的红色给去掉了。 > > 问题出在什么地方? > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060715/e7df51d6/attachment.html
2006年07月15日 星期六 12:07
感谢,在网上查了一下,这样可以解决png的贴图,但如果是gif,
还需要这样:
mask = ''
if (i.mode == 'P'):
colorTable = [255]*256
colorTable[0] = 0 #anything black (0) will be made transparent
mask = i.point (colorTable, '1') #make the transparency mask
if (i.mode == 'RGBA'):
mask = i
if mask:
img.paste(i,(0,0), mask)
else:
img.paste(i,(0,0))
在 06-7-15,swordsp<sparas2006 at gmail.com> 写道:
>
>
> On 7/15/06, chen arthur <agakong at gmail.com> wrote:
> > 先把背景填成红色,再在图上贴一个有透明部分的png图,希望把透明效果实现出来(就是把后面的红色透出来):
> >
> > im = Image.new('RGBA',(100,100),color=(255,255,255))
> > draw = ImageDraw.Draw(im)
> > draw.rectangle((0,0,100,100),fill="#cc0000")
> > i = Image.open('test.png ')
> > im.paste(i,(0,0))
>
>
> im.paste(i,i) #等价于im.paste(i,None,i)
> 第一个参数image中只使用了其颜色信息,透明度的信息是通过第三个参数mask传进去的。
> 这里的确有一点不太直观,我第一次也弄糊涂了。
>
> > del draw
> > im.save('done.png')
> >
> > 但最后得到的done.png,贴上去的部分有透明,但不是把背景的红色透出来,而是把先前的红色给去掉了。
> >
> > 问题出在什么地方?
> >
> >
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to
> python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to
> python-chinese-request at lists.python.cn
> Detail Info:
> http://python.cn/mailman/listinfo/python-chinese
>
>
2006年07月15日 星期六 12:10
还有一个中文显示的问题,用的是微软的simsun.ttc,
但好像字体大小是10可以,10以上显示的字都是花的?
哪位碰到过这个事情?
f = ImageFont.FreeTypeFont('simsun.ttc',14)
draw.text((x,y),unicode('中国','utf-8'),font=f,fill="#000000")
在 06-7-15,chen arthur<agakong at gmail.com> 写道:
> 感谢,在网上查了一下,这样可以解决png的贴图,但如果是gif,
> 还需要这样:
> mask = ''
> if (i.mode == 'P'):
> colorTable = [255]*256
> colorTable[0] = 0 #anything black (0) will be made transparent
> mask = i.point (colorTable, '1') #make the transparency mask
> if (i.mode == 'RGBA'):
> mask = i
> if mask:
> img.paste(i,(0,0), mask)
> else:
> img.paste(i,(0,0))
>
> 在 06-7-15,swordsp<sparas2006 at gmail.com> 写道:
> >
> >
> > On 7/15/06, chen arthur <agakong at gmail.com> wrote:
> > > 先把背景填成红色,再在图上贴一个有透明部分的png图,希望把透明效果实现出来(就是把后面的红色透出来):
> > >
> > > im = Image.new('RGBA',(100,100),color=(255,255,255))
> > > draw = ImageDraw.Draw(im)
> > > draw.rectangle((0,0,100,100),fill="#cc0000")
> > > i = Image.open('test.png ')
> > > im.paste(i,(0,0))
> >
> >
> > im.paste(i,i) #等价于im.paste(i,None,i)
> > 第一个参数image中只使用了其颜色信息,透明度的信息是通过第三个参数mask传进去的。
> > 这里的确有一点不太直观,我第一次也弄糊涂了。
> >
> > > del draw
> > > im.save('done.png')
> > >
> > > 但最后得到的done.png,贴上去的部分有透明,但不是把背景的红色透出来,而是把先前的红色给去掉了。
> > >
> > > 问题出在什么地方?
> > >
> > >
> >
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese at lists.python.cn
> > Subscribe: send subscribe to
> > python-chinese-request at lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request at lists.python.cn
> > Detail Info:
> > http://python.cn/mailman/listinfo/python-chinese
> >
> >
>
2006年07月15日 星期六 13:06
哪有pil的中文资料呢 请问 在06-7-15,chen arthur <agakong at gmail.com> 写道: > > 还有一个中文显示的问题,用的是微软的simsun.ttc, > 但好像字体大小是10可以,10以上显示的字都是花的? > 哪位碰到过这个事情? > > f = ImageFont.FreeTypeFont('simsun.ttc',14) > draw.text((x,y),unicode('中国','utf-8'),font=f,fill="#000000") > > > 在 06-7-15,chen arthur<agakong at gmail.com> 写道: > > 感谢,在网上查了一下,这样可以解决png的贴图,但如果是gif, > > 还需要这样: > > mask = '' > > if (i.mode == 'P'): > > colorTable = [255]*256 > > colorTable[0] = 0 #anything black (0) will be made transparent > > mask = i.point (colorTable, '1') #make the transparency mask > > if (i.mode == 'RGBA'): > > mask = i > > if mask: > > img.paste(i,(0,0), mask) > > else: > > img.paste(i,(0,0)) > > > > 在 06-7-15,swordsp<sparas2006 at gmail.com> 写道: > > > > > > > > > On 7/15/06, chen arthur <agakong at gmail.com> wrote: > > > > 先把背景填成红色,再在图上贴一个有透明部分的png图,希望把透明效果实现出来(就是把后面的红色透出来): > > > > > > > > im = Image.new('RGBA',(100,100),color=(255,255,255)) > > > > draw = ImageDraw.Draw(im) > > > > draw.rectangle((0,0,100,100),fill="#cc0000") > > > > i = Image.open('test.png ') > > > > im.paste(i,(0,0)) > > > > > > > > > im.paste(i,i) #等价于im.paste(i,None,i) > > > 第一个参数image中只使用了其颜色信息,透明度的信息是通过第三个参数mask传进去的。 > > > 这里的确有一点不太直观,我第一次也弄糊涂了。 > > > > > > > del draw > > > > im.save('done.png') > > > > > > > > 但最后得到的done.png,贴上去的部分有透明,但不是把背景的红色透出来,而是把先前的红色给去掉了。 > > > > > > > > 问题出在什么地方? > > > > > > > > > > > > > > > > > _______________________________________________ > > > python-chinese > > > Post: send python-chinese at lists.python.cn > > > Subscribe: send subscribe to > > > python-chinese-request at lists.python.cn > > > Unsubscribe: send unsubscribe to > > > python-chinese-request at lists.python.cn > > > Detail Info: > > > http://python.cn/mailman/listinfo/python-chinese > > > > > > > > > > _______________________________________________ > python-chinese > Post: send python-chinese at lists.python.cn > Subscribe: send subscribe to python-chinese-request at lists.python.cn > Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn > Detail Info: http://python.cn/mailman/listinfo/python-chinese > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060715/c35b7255/attachment.html
Zeuux © 2025
京ICP备05028076号