crocparty/pytools/shared.py

17 lines
477 B
Python

from PIL import Image
from jinja2 import Environment, BaseLoader, select_autoescape
templates = Environment(
loader=BaseLoader(),
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())