Add replace_color.

This commit is contained in:
voussoir 2022-02-01 18:23:59 -08:00
parent 797b4efd89
commit c1cba4f287
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -73,6 +73,15 @@ def pad_to_square(image, background_color=None) -> PIL.Image:
new_image.paste(image, (diff_w, diff_h)) new_image.paste(image, (diff_w, diff_h))
return new_image 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): def rotate_by_exif(image):
''' '''
Rotate the image according to its exif data, so that it will display Rotate the image according to its exif data, so that it will display