Skip to content

Instantly share code, notes, and snippets.

@hakatashi
Created January 31, 2015 13:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hakatashi/c2a6eed45f7372e5016e to your computer and use it in GitHub Desktop.
Save hakatashi/c2a6eed45f7372e5016e to your computer and use it in GitHub Desktop.
from PIL import Image
omote = Image.open('omote.png', 'r')
ura = Image.open('ura.png', 'r')
dest = Image.new('RGBA', omote.size)
(width, height) = omote.size
for x in range(width):
for y in range(height):
omotepx = omote.getpixel((x, y))[0]
urapx = ura.getpixel((x, y))[0]
alpha = 255 + urapx - omotepx
if alpha == 0:
val = 255
else:
val = 255 * urapx / alpha
dest.putpixel((x, y), (val, val, val, alpha))
dest.save('dest.png', 'PNG')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment