diff options
author | Julian T <julian@jtle.dk> | 2021-04-17 00:00:32 +0200 |
---|---|---|
committer | Julian T <julian@jtle.dk> | 2021-04-17 00:00:32 +0200 |
commit | 2f752f51de99eb82fb953290b4e1289ca7a5e15f (patch) | |
tree | 8e1f91fd1e7ae01d73d558504dd0db357c5976d7 | |
parent | cb8d6760edc39fc49015129d5e42b7e14e250e95 (diff) |
Keep correct aspect on pictures
-rwxr-xr-x | build.py | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -9,7 +9,6 @@ import hashlib import glob imagereg = re.compile("([a-z0-9]*)\\..*") -resreg = re.compile("([0-9]*)x([0-9]*)") def hashfile(fname): @@ -23,8 +22,7 @@ def hashfile(fname): def parse_res(res): - m = resreg.match(res) - return (int(m.group(1)), int(m.group(2))) + return int(res) class FileLoader(jinja2.BaseLoader): @@ -79,7 +77,10 @@ class ImageLocation: print(f"Converting file {imgname} to {fname}") im = PIL.Image.open(imgname) - im = im.resize(settings["res"], PIL.Image.ANTIALIAS) + + width = settings["res"] + res = (width, int((im.size[1] / im.size[0]) * width)) + im = im.resize(res, PIL.Image.ANTIALIAS) tmpname = f"{self.tmpname}.{settings['ext']}" im.save(tmpname) @@ -196,7 +197,7 @@ class Renderer: parser = argparse.ArgumentParser() parser.add_argument("--dest", "-d", default="build", help="where to put resulting files") -parser.add_argument("--size", "-s", default="1920x1080", help="size to scale web images to") +parser.add_argument("--size", "-s", default="1920", help="size to scale web images to") parser.add_argument("--commit", "-g", help="git commit hash to announce") parser.add_argument("--clean", help="clean unused image files", action="store_true") parser.add_argument("--config", "-c", default="imginfo.yml", help="where to load image definitions from") |