Skip to content

Instantly share code, notes, and snippets.

@jackyyf
Created April 23, 2015 04:20
Show Gist options
  • Save jackyyf/ce4fd2e207e00da18575 to your computer and use it in GitHub Desktop.
Save jackyyf/ce4fd2e207e00da18575 to your computer and use it in GitHub Desktop.
Gist by paste.py @ 2015-04-23 12:20:25.228771
from PIL import Image
src_color = (231, 20, 26)
target_color = (0, 0, 0xFF)
im = Image.open('9_019.png')
w, h = im.size
for x in range(w):
for y in range(h):
r, g, b, a = im.getpixel((x, y))
d = abs(r - src_color[0]) + abs(g - src_color[1]) + abs(b - src_color[2])
if d < 20:
r, g, b = target_color
im.putpixel((x, y), (r, g, b, a))
im.save('9_019_gm.png')
@iamlixiao
Copy link

这段代码还是存在缺陷的。把你生成的图片放到最大,可以发现仍然存在红色的像素。我把它改进了一下:https://gist.github.com/iamlixiao/9490eed1929f340ffd32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment