[Image-SIG] Transparent paste - another problem

Florian Höch lists+Image_SIG at hoech.org
Fri Oct 10 11:21:26 CEST 2008


:) Another quick update. Use ImageChops.lighter instead of 
ImageChops.add (same arguments). That way the mask quality should not 
wear down when adding an alpha channel that is partially the same as the 
existing one.

Regards,

Florian

Szymon Kosok schrieb:
> Hello,
> 
> You are my hero, Florian. :) That works! :) Thanks.
> 
> Best regards,
> Szymon
> 
> 2008/10/10 Florian Höch <lists+Image_SIG at hoech.org>:
>> Ok, I think I got it. The alpha channel needs to be updated during and
>> inserted after the paste operations.
>>
>> from PIL import Image, ImageChops
>>
>> foo = Image.open("bar.png")
>> alpha = foo.split()[-1]
>>
>> for p in w:
>>    baz = Image.open(p.element.binary.path)
>>    foo.paste(baz, (p.x, p.y), baz)
>>    alpha = ImageChops.add(alpha, baz.split()[-1])
>>
>> foo.putalpha(alpha)
>>
>> Regards,
>>
>> Florian
>>
>> Szymon Kosok schrieb:
>>> Hi,
>>>
>>> Ok. So here is some baz:
>>>
>>> http://i.wonderlife.pl/cache/ubranie-83-620.png
>>> http://i.wonderlife.pl/cache/ubranie-84-620.png
>>>
>>> And this is foo:
>>>
>>> http://i.wonderlife.pl/img/ciala/mc.png
>>>
>>> Regards,
>>> Szymon
>>>
>>> 2008/10/8 Florian Höch <lists+Image_SIG at hoech.org>:
>>>> Hi,
>>>>
>>>> without seeing the original foo and at least some of the baz images, it's
>>>> hard to tell how to achieve what you're looking for. I'd assume you want
>>>> some sort of "adaptive multiplication", where only transparent parts are
>>>> "multiplied over" the existing image and fully opaque parts "knock out"
>>>> everything under it.
>>>>
>>>> Regards,
>>>>
>>>> Florian
>>>>
>>>> Szymon Kosok schrieb:
>>>>> Hi,
>>>>>
>>>>> I have another problem with PIL and transparent images. I have such
>>>>> code:
>>>>>
>>>>>       foo = Image.open("bar.png")
>>>>>
>>>>>       for p in w:
>>>>>
>>>>>           baz = Image.open(p.element.binary.path)
>>>>>
>>>>>           foo.paste(baz, (p.x, p.y), baz)
>>>>>
>>>>> And the problem is... every baz (some of them are semi-transparent) is
>>>>> transparent over every previous element.
>>>>>
>>>>> Maybe I'll show what I want, and what I got:
>>>>>
>>>>> http://i36.tinypic.com/2efjlaw.png - this is what I want,
>>>>> http://i38.tinypic.com/11glf6t.png - and this what I get.
>>>>>
>>>>> Any hints?
>>>>>
>>>>> Best regards,
>>>>> Szymon
>>>>> _______________________________________________
>>>>> Image-SIG maillist  -  Image-SIG at python.org
>>>>> http://mail.python.org/mailman/listinfo/image-sig
>>>> _______________________________________________
>>>> Image-SIG maillist  -  Image-SIG at python.org
>>>> http://mail.python.org/mailman/listinfo/image-sig
>>>>
>> _______________________________________________
>> Image-SIG maillist  -  Image-SIG at python.org
>> http://mail.python.org/mailman/listinfo/image-sig
>>
> _______________________________________________
> Image-SIG maillist  -  Image-SIG at python.org
> http://mail.python.org/mailman/listinfo/image-sig



More information about the Image-SIG mailing list