From c1cba4f287cdfe4afa6658867653c52e240facf8 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 1 Feb 2022 18:23:59 -0800 Subject: [PATCH] Add replace_color. --- voussoirkit/imagetools.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/voussoirkit/imagetools.py b/voussoirkit/imagetools.py index ba19cff..58b9aad 100644 --- a/voussoirkit/imagetools.py +++ b/voussoirkit/imagetools.py @@ -73,6 +73,15 @@ def pad_to_square(image, background_color=None) -> PIL.Image: new_image.paste(image, (diff_w, diff_h)) return new_image +def replace_color(image, from_color, to_color): + image = image.copy() + pixels = image.load() + for y in range(image.size[1]): + for x in range(image.size[0]): + if pixels[x, y] == from_color: + pixels[x, y] = to_color + return image + def rotate_by_exif(image): ''' Rotate the image according to its exif data, so that it will display