Created
October 23, 2017 18:54
-
-
Save rghossi/92b7e910f9a918c3a8e1f8941a108da4 to your computer and use it in GitHub Desktop.
Script to replace png image color
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
#!/usr/bin/env python | |
import sys | |
import numpy as np | |
from PIL import Image | |
if len(sys.argv) != 2: | |
print 'Invalid number of arguments' | |
sys.exit() | |
NEW_PATH = 'images/fig.png' | |
# R_OLD, G_OLD, B_OLD = (255, 255, 255) | |
R_NEW, G_NEW, B_NEW = (255, 255, 255) | |
im = Image.open(sys.argv[1]) | |
pixels = im.load() | |
width, height = im.size | |
for x in range(width): | |
for y in range(height): | |
r, g, b, a = pixels[x, y] | |
# if (r, g, b) == (R_OLD, G_OLD, B_OLD): | |
pixels[x, y] = (R_NEW, G_NEW, B_NEW, a) | |
im.save(NEW_PATH) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment