Move the image loader to shared

This commit is contained in:
Pyrex 2024-02-26 16:05:07 -08:00
parent 72599b7d00
commit d05e382063
2 changed files with 26 additions and 22 deletions

View File

@ -25,14 +25,7 @@ def main(font_name, n_glyphs, fname_png, fname_c):
def load_glyphs(fname_png: str): def load_glyphs(fname_png: str):
with Image.open(fname_png) as im: width, height, data = shared.load_image(fname_png)
width = im.width
height = im.height
assert width % 8 == 0, "width must be a multiple of 8"
assert height % 8 == 0, "height must be a multiple of 8"
data = list(im.convert("RGBA").getdata())
monochrome = [pixel_to_monochrome(p) for p in data] monochrome = [pixel_to_monochrome(p) for p in data]
glyphs = [] glyphs = []

View File

@ -1,6 +1,17 @@
from PIL import Image
from jinja2 import Environment, BaseLoader, select_autoescape from jinja2 import Environment, BaseLoader, select_autoescape
templates = Environment( templates = Environment(
loader=BaseLoader(), loader=BaseLoader(),
autoescape=select_autoescape(), autoescape=select_autoescape(),
) )
def load_image(fname):
with Image.open(fname) as im:
width = im.width
height = im.height
assert width % 8 == 0, "width must be a multiple of 8"
assert height % 8 == 0, "height must be a multiple of 8"
return width, height, list(im.convert("RGBA").getdata())