Created
April 23, 2015 04:20
-
-
Save jackyyf/ce4fd2e207e00da18575 to your computer and use it in GitHub Desktop.
Gist by paste.py @ 2015-04-23 12:20:25.228771
This file contains 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 | |
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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这段代码还是存在缺陷的。把你生成的图片放到最大,可以发现仍然存在红色的像素。我把它改进了一下:https://gist.github.com/iamlixiao/9490eed1929f340ffd32