Skip to content

Instantly share code, notes, and snippets.

@tinyfpga
Created May 13, 2018 18:59
Show Gist options
  • Save tinyfpga/59a969616af340c2099ed1149d8afa7a to your computer and use it in GitHub Desktop.
Save tinyfpga/59a969616af340c2099ed1149d8afa7a to your computer and use it in GitHub Desktop.
def create_layers(img, name):
from PIL import Image
def combine(img, layers):
result = Image.new('RGB', img.size, 0x000000)
for i in range(img.size[0]):
for j in range(img.size[1]):
if img.getpixel((i, j)) in layers:
result.putpixel((i, j), 0xFFFFFF)
else:
result.putpixel((i, j), 0x000000)
return result
img_q = img.quantize(5)
combine(img_q, [4, 2, 1]).save(name + "_copper.png")
combine(img_q, [2, 3]).save(name + "_soldermask.png")
combine(img_q, [1]).save(name + "_silkscreen.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment