From a5f586f1bee2ffa62227ec9e75b9be54f4f0d6f2 Mon Sep 17 00:00:00 2001 From: Jaka Date: Mon, 29 Nov 2021 17:59:45 +0100 Subject: [PATCH] Changed the image assembly into 2D instead of vertical. --- deploy.py | 29 ++++++++++++++-------- source/filelist_template.xml | 3 ++- source/sunken_tapes_style_ita_template.xml | 2 +- source/sunken_tapes_style_template.xml | 2 +- source/sunken_tapes_template.xml | 8 +++--- 5 files changed, 26 insertions(+), 18 deletions(-) diff --git a/deploy.py b/deploy.py index 9593d3c..6c4531b 100644 --- a/deploy.py +++ b/deploy.py @@ -9,6 +9,7 @@ import sys import time import logging import certifi +import math from PIL import Image from mutagen.oggvorbis import OggVorbis from distutils.dir_util import copy_tree @@ -143,23 +144,24 @@ def fetch_and_cut_song(tape, ffmpeg_version): def assemble_png_image(tapes, icons=False): if icons: img_names = [f"./source/images/{tape['identifier']}_icon.png" for tape in tapes] - images = [Image.open("./source/images/boombox_icon.png")] else: img_names = [f"./source/images/{tape['identifier']}.png" for tape in tapes] - images = [] - images += [Image.open(x) for x in img_names] + images = [Image.open(x) for x in img_names] widths, heights = zip(*(i.size for i in images)) - total_width = max(widths) - max_height = sum(heights) + columns = int((len(images))**0.5) + rows = int(math.ceil(len(images) / columns)) + + total_width = max(widths) * columns + max_height = max(heights) * rows new_im = Image.new('RGBA', (total_width, max_height)) - y_offset = 0 - for im in images: - new_im.paste(im, (0, y_offset)) - y_offset += im.size[1] + for i, im in enumerate(images): + x_offset = max(widths) * (i % columns) + y_offset = max(heights) * math.floor(i / columns) + new_im.paste(im, (x_offset, y_offset)) if icons: new_im.save("./build/icons.png") @@ -199,6 +201,7 @@ def prepare_images(data, config): logging.info(f"copying other images") shutil.copy("./source/images/boombox.png", "./build/boombox.png") + shutil.copy("./source/images/boombox_icon.png", "./build/boombox_icon.png") shutil.copy("./source/images/PreviewImage.png", "./build/PreviewImage.png") @@ -213,6 +216,9 @@ def build_xml_code(data, config): condition_delta = [f"{1 / use_length:0.5f}" for use_length in use_lengths] affliction_delta = [100 / song_length for song_length in song_lengths] + columns = int((len(data))**0.5) + positions = [{"column": i % columns, "row": math.floor(i / columns)} for i in range(len(data))] + logging.info(f"creating jinja environment") # create jinja2 environment j2env = j2.Environment(loader=j2.FileSystemLoader(Path("."))) @@ -237,11 +243,12 @@ def build_xml_code(data, config): output_file.write(template1.render(tapes=data, config=config, condition_delta=condition_delta, affliction_delta=affliction_delta, - song_lengths=song_lengths)) + song_lengths=song_lengths, + positions=positions)) with open(f"./build/{config['slug']}_style.xml", "w+", encoding="utf8") as output_file: # render the template - output_file.write(template2.render(tapes=data, config=config)) + output_file.write(template2.render(tapes=data, config=config, positions=positions)) def deploy(config): diff --git a/source/filelist_template.xml b/source/filelist_template.xml index bb35d81..14dea09 100644 --- a/source/filelist_template.xml +++ b/source/filelist_template.xml @@ -5,7 +5,8 @@ - {% for tape in tapes %} + + {% for tape in tapes %} {% endfor %} diff --git a/source/sunken_tapes_style_ita_template.xml b/source/sunken_tapes_style_ita_template.xml index 0dd8bb1..213d95c 100644 --- a/source/sunken_tapes_style_ita_template.xml +++ b/source/sunken_tapes_style_ita_template.xml @@ -198,7 +198,7 @@ {% for tape in tapes %} <{{ config['slug'] }}_cover_{{ tape.identifier }} color="255,255,255,255" textcolor="0,0,0,255"> - + {% endfor %} diff --git a/source/sunken_tapes_style_template.xml b/source/sunken_tapes_style_template.xml index 379ff82..48097d2 100644 --- a/source/sunken_tapes_style_template.xml +++ b/source/sunken_tapes_style_template.xml @@ -200,7 +200,7 @@ {% for tape in tapes %} <{{ config['slug'] }}_cover_{{ tape.identifier }} color="255,255,255,255" textcolor="0,0,0,255"> - + {% endfor %} diff --git a/source/sunken_tapes_template.xml b/source/sunken_tapes_template.xml index 3659851..5f794a6 100644 --- a/source/sunken_tapes_template.xml +++ b/source/sunken_tapes_template.xml @@ -24,7 +24,7 @@ - + @@ -78,7 +78,7 @@ - + @@ -129,8 +129,8 @@ - - + +