Re: [Image-SIG] I'm confused by alpha blending.
I found the problem, thanks to the code you posted. My destination image was "RGBA", and I was viewing it in a web browser. Most of the image had an opaque alpha channel, but where I had drawn the drop shadows, it had the shadow's alpha values, so the white of the browser was showing through. This isn't the most intuitive way for alpha drawing to work. I guess I could see it both ways: if the destination is opaque, it should stay opaque, or drawing pixels onto a destination takes all the values from the source. In any case, changing my destination image from RGBA to RGB solved the problem. Thanks. --Ned. Fredrik Lundh wrote: are you 100% sure that the source pixels are black ? a quick way to find out is to do print shadow.convert("RGB").getcolors() ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig -- Ned Batchelder, http://nedbatchelder.com ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] I'm confused by alpha blending.
(I send this days ago, and was told it was subject to moderation because of a suspicious header). I found the problem, thanks to the code you posted. My destination image was "RGBA", and I was viewing it in a web browser. Most of the image had an opaque alpha channel, but where I had drawn the drop shadows, it had the shadow's alpha values, so the white of the browser was showing through. This isn't the most intuitive way for alpha drawing to work. I guess I could see it both ways: if the destination is opaque, it should stay opaque, or drawing pixels onto a destination takes all the values from the source. In any case, changing my destination image from RGBA to RGB solved the problem. Thanks. --Ned. Fredrik Lundh wrote: Is there something I am doing wrong? sounds confusing, indeed. are you 100% sure what happens what happens did you get anywhere with this ? ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig -- Ned Batchelder, http://nedbatchelder.com ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] I'm confused by alpha blending.
>> Is there something I am doing wrong? > > sounds confusing, indeed. > > are you 100% sure > > what happens > > what happens did you get anywhere with this ? ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] I'm confused by alpha blending.
> are you 100% sure that the source pixels are black ? a quick way to find out is to do print shadow.convert("RGB").getcolors() ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
Re: [Image-SIG] I'm confused by alpha blending.
Ned Batchelder wrote: > I'm using PIL to composite a drop shadow onto an image. The blending > isn't working the way I would expect. The drop shadow image itself has > all black pixels, with all of the interesting stuff happening in the > alpha channel. I'm using Image.paste to draw the drop shadow, by > specifying the shadow png as both the image and the mask. > > When I do this on a pure black image, the shadow lightens the pixels! > For example, a black existing pixel gets a shadow pixel that is black > with alpha value of 152 decimal. The result should be black (since both > the source and the destination are black, how can the alpha channel > lighten the pixel?), but it comes out with a value of 100 decimal. > > When I graph the background color against the resulting color (using a > fixed black shadow pixel with 152 alpha), the result is linear, but as I > say, it lightens black pixels inexplicably. > > Is there something I am doing wrong? sounds confusing, indeed. are you 100% sure that the source pixels are black ? what happens if you do paste("black", shadow) on a black image ? what happens on your machine if you do: >>> from PIL import Image >>> Image.VERSION '1.1.5' >>> bg = Image.new("RGB", (100, 100), "black") >>> bg.getcolors() [(1, (0, 0, 0))] >>> shadow = Image.new("RGB", (100, 100), 0) >>> alpha = Image.new("L", (100, 100), None) >>> alpha.putdata(range(0,200,2)*100) >>> shadow.putalpha(alpha) >>> shadow.mode 'RGBA' >>> len(shadow.getcolors()) 100 >>> bg.paste(shadow, shadow) >>> bg.getcolors() [(1, (0, 0, 0))] ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig
[Image-SIG] I'm confused by alpha blending.
I'm using PIL to composite a drop shadow onto an image. The blending isn't working the way I would expect. The drop shadow image itself has all black pixels, with all of the interesting stuff happening in the alpha channel. I'm using Image.paste to draw the drop shadow, by specifying the shadow png as both the image and the mask. When I do this on a pure black image, the shadow lightens the pixels! For example, a black existing pixel gets a shadow pixel that is black with alpha value of 152 decimal. The result should be black (since both the source and the destination are black, how can the alpha channel lighten the pixel?), but it comes out with a value of 100 decimal. When I graph the background color against the resulting color (using a fixed black shadow pixel with 152 alpha), the result is linear, but as I say, it lightens black pixels inexplicably. Is there something I am doing wrong? -- Ned Batchelder, http://nedbatchelder.com ___ Image-SIG maillist - Image-SIG@python.org http://mail.python.org/mailman/listinfo/image-sig