From b87b6cc9c63ce35c215e2aadbf49e0a5e4aed9d5 Mon Sep 17 00:00:00 2001 From: Marco van Dijk Date: Fri, 9 Jul 2021 22:22:20 +0200 Subject: [PATCH] added variables for resize behaviour --- lib/config.py | 4 +++- lib/dataStructures.py | 13 ++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/config.py b/lib/config.py index f96ab04..1aa3398 100644 --- a/lib/config.py +++ b/lib/config.py @@ -49,7 +49,9 @@ def initConfig(): 'topMargin': 50, 'leftMargin': 50, 'rightMargin': 50, - 'tryToShrinkRatio' : 0.25 + 'tryToShrinkRatio' : 0.25, + 'lowestwhitespaceonwidthratioallowed': 0.90, + 'hightestwhitespaceonwidthratioallowed': 0.40 } # (if CMD arguments: load CMD arguments to override specific settings) with open('config.ini', 'w') as configfile: diff --git a/lib/dataStructures.py b/lib/dataStructures.py index ff2d753..907bc9f 100644 --- a/lib/dataStructures.py +++ b/lib/dataStructures.py @@ -221,8 +221,15 @@ class Song: self.metadataFontsize = int(configObj['metaFontWeight']) self.metadataFontFamily = configObj['metafontfamily'] self.fontMetadata = ImageFont.truetype(self.metadataFontFamily, self.metadataFontsize) - # percentageof missing whitespace and total page height + # Allowed whitespace to total width ratios. Makes stuff smaller but fit on less pages, probably + # percentage of missing whitespace on total page height it wants before it tries to resize down self.tryToShrinkRatio = float(configObj['tryToShrinkRatio']) + # Setting this makes sure that the largest section on the page fills at least this percentage of total width + # The higher this is, the more it is allowed to shrink + self.lowestWhitespaceOnWidthRatioAllowed = float(configObj['lowestWhitespaceOnWidthRatioAllowed']) + # Some sections are very small, so the highest whitespace can be very large. + # It is advised to keep this value relatively small + self.hightestWhitespaceOnWidthRatioAllowed = float(configObj['hightestWhitespaceOnWidthRatioAllowed']) @@ -351,11 +358,11 @@ class Song: biggestWhitespace = whitespaceOnWidth # Sections vary in width, some are very small to begin with # Since (almost empty) lines will result in large whitespace sizes, we are less strict on checking that - if biggestWhitespace / self.imageWidth > 0.9: + if biggestWhitespace / self.imageWidth > self.lowestWhitespaceOnWidthRatioAllowed: print("Stopping resizing down, since the smallest section has {}% whitespace on the width of the image".format((biggestWhitespace / self.imageWidth )* 100)) return False # But the largest section on the page should be able to fit at least half of the available page - if smallestWhitespace / self.imageWidth > 0.4: + if smallestWhitespace / self.imageWidth > self.hightestWhitespaceOnWidthRatioAllowed: print("Stopping resizing down, since we largest section has {}% whitespace on the width of the image".format((smallestWhitespace / self.imageWidth )* 100)) return False # get first section on next page, if we have a next page to begin with