Created
June 18, 2015 02:29
-
-
Save mlabbe/e2e89a017dca7c16c150 to your computer and use it in GitHub Desktop.
Premultiply Alpha
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from PIL import Image | |
| import numpy | |
| import glob | |
| for path in glob.glob("*.png"): | |
| print(path) | |
| im = Image.open(path).convert('RGBA') | |
| a = numpy.fromstring(im.tostring(), dtype=numpy.uint8) | |
| alphaLayer = a[3::4] / 255.0 | |
| a[::4] *= alphaLayer | |
| a[1::4] *= alphaLayer | |
| a[2::4] *= alphaLayer | |
| im = Image.fromstring("RGBA", im.size, a.tostring()) | |
| im.save(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment