Note that there are some explanatory texts on larger screens.

plurals
  1. POColor to transparency - programmatically
    primarykey
    data
    text
    <p>you might know the "Color to transparency" effect of professional image editing programs like Photoshop. How is this effect done? I want to add some transparency to my images programmatically with Python (and for testing PIL, because I can check with generated images). This effect is going to be used for some fractal things, so here's my current code: </p> <pre><code>i = "i.png" o = "o.png" key = (0, 0, 0, 255) from PIL import Image as I _i = I.open(i) _ii = _i.load() _o = I.new("RGBA", _i.size) _oo = _o.load() for x in range(0, _i.size[0]): for y in range(0, _i.size[1]): col = list(_ii[x, y]) for i in range(0, 4): col[i] = abs(col[i] - key[i]) _oo[x, y] = tuple(col) _o.save(o) </code></pre> <p>I thought of subtracting the both colors, but i end up with black images (loses all alpha). Another thought was to double the original color and check if the key is lower, like reverse-mixing the two colors.</p> <p>So, do you have any ideas?</p> <p><strong>EDIT</strong></p> <p><img src="https://i.stack.imgur.com/RQTAF.png" alt="Example of &quot;Color to transparency&quot;"></p> <p>This effect was done with GIMP using it's "Color to transparency" function. I selected #FFF to be transparent and GIMP somehow made white to transparent, without ignoring the color of the pixel at first. This is, what I actually want to do, make a color in an image transparent, like in the image. </p> <p>(I added a black background to the second image, so you know it's transparent. The original image was just like the first one, white background, slightly green surrounding, black center)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload