Skip to content

Instantly share code, notes, and snippets.

@dietercastel
Last active January 6, 2020 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dietercastel/03710b79328bafc3df60ea938c63c056 to your computer and use it in GitHub Desktop.
Save dietercastel/03710b79328bafc3df60ea938c63c056 to your computer and use it in GitHub Desktop.
Convert black and white image to black & red.
# This script coverts a black & white image to an image with new colors.
from PIL import ImageOps, Image
imgPath = "testImg.png"
blackColor = (255,0,0,0)
whiteColor = (0,0,0,255)
img = Image.open(imgPath).convert("L")
# Black pxl, white pxl
newImg = ImageOps.colorize(img,blackColor,whiteColor)
#ImageOps.crop(newImg,border=55).show()
newImg.show()
newImg.save("Colorified.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment