Convert RGB to black OR white

Scaling to Black and White Convert to grayscale and then scale to white or black (whichever is closest). Original: Result: Pure Pillow implementation Install pillow if you haven’t already: $ pip install pillow Pillow (or PIL) can help you work with images effectively. from PIL import Image col = Image.open(“cat-tied-icon.png”) gray = col.convert(‘L’) bw = … Read more

How do you composite an image onto another image with PIL in Python?

This can be accomplished with an Image instance’s paste method: from PIL import Image img = Image.open(‘/path/to/file’, ‘r’) img_w, img_h = img.size background = Image.new(‘RGBA’, (1440, 900), (255, 255, 255, 255)) bg_w, bg_h = background.size offset = ((bg_w – img_w) // 2, (bg_h – img_h) // 2) background.paste(img, offset) background.save(‘out.png’) This and many other PIL … Read more