From 02b6f3649520a0c5a664e75634304e3d133fcc66 Mon Sep 17 00:00:00 2001 From: Thesacraft Date: Tue, 2 Jul 2024 13:18:39 +0200 Subject: [PATCH 01/10] Add font thumbnail preview support --- tagstudio/src/core/constants.py | 9 +++++++++ tagstudio/src/qt/widgets/thumb_renderer.py | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tagstudio/src/core/constants.py b/tagstudio/src/core/constants.py index d07489aa6..ae5a1fe8a 100644 --- a/tagstudio/src/core/constants.py +++ b/tagstudio/src/core/constants.py @@ -7,6 +7,13 @@ COLLAGE_FOLDER_NAME: str = "collages" LIBRARY_FILENAME: str = "ts_library.json" +FONT_SAMPLE_TEXT: str = """ABCDEFGHIJKLM +NOPQRSTUVWXYZ +abcdefghijklm +nopqrstuvwxyz +0123456789 +!?.@$%(){}[]""" + # TODO: Turn this whitelist into a user-configurable blacklist. IMAGE_TYPES: list[str] = [ ".png", @@ -107,6 +114,7 @@ ] PROGRAM_TYPES: list[str] = [".exe", ".app"] SHORTCUT_TYPES: list[str] = [".lnk", ".desktop", ".url"] +FONT_TYPES: list[str] = [".ttf", ".otf", ".woff"] ALL_FILE_TYPES: list[str] = ( IMAGE_TYPES @@ -118,6 +126,7 @@ + ARCHIVE_TYPES + PROGRAM_TYPES + SHORTCUT_TYPES + + FONT_TYPES ) BOX_FIELDS = ["tag_box", "text_box"] diff --git a/tagstudio/src/qt/widgets/thumb_renderer.py b/tagstudio/src/qt/widgets/thumb_renderer.py index 1e6a3ad17..f088e1442 100644 --- a/tagstudio/src/qt/widgets/thumb_renderer.py +++ b/tagstudio/src/qt/widgets/thumb_renderer.py @@ -25,9 +25,11 @@ from src.qt.helpers.gradient import four_corner_gradient_background from src.core.constants import ( PLAINTEXT_TYPES, + FONT_TYPES, VIDEO_TYPES, IMAGE_TYPES, RAW_IMAGE_TYPES, + FONT_SAMPLE_TEXT, ) from src.core.utils.encoding import detect_char_encoding @@ -183,7 +185,14 @@ def render( text = text_file.read(256) bg = Image.new("RGB", (256, 256), color="#1e1e1e") draw = ImageDraw.Draw(bg) - draw.text((16, 16), text, file=(255, 255, 255)) + draw.text((16, 16), text, fill=(255, 255, 255)) + image = bg + # Fonts ======================================================== + elif _filepath.suffix.lower() in FONT_TYPES: + bg = Image.new("RGB", (256, 256), color="#1e1e1e") + font = ImageFont.truetype(_filepath, 25) + draw = ImageDraw.Draw(bg) + draw.text((16, 16), FONT_SAMPLE_TEXT, font=font) image = bg # 3D =========================================================== # elif extension == 'stl': From 59476d8032ef7209a21a412ccccb0ec0eecf9922 Mon Sep 17 00:00:00 2001 From: Thesacraft Date: Tue, 2 Jul 2024 14:42:37 +0200 Subject: [PATCH 02/10] Add multiple font sizes to thumbnail --- tagstudio/src/core/constants.py | 18 ++++++++++++------ tagstudio/src/qt/widgets/thumb_renderer.py | 13 +++++++++++-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/tagstudio/src/core/constants.py b/tagstudio/src/core/constants.py index ae5a1fe8a..e4b12eb80 100644 --- a/tagstudio/src/core/constants.py +++ b/tagstudio/src/core/constants.py @@ -7,12 +7,18 @@ COLLAGE_FOLDER_NAME: str = "collages" LIBRARY_FILENAME: str = "ts_library.json" -FONT_SAMPLE_TEXT: str = """ABCDEFGHIJKLM -NOPQRSTUVWXYZ -abcdefghijklm -nopqrstuvwxyz -0123456789 -!?.@$%(){}[]""" +FONT_SAMPLE_TEXT: str = """ABCDEF +GHIJKLM +NOPQRS +TUVWXYZ +abcdef +ghijklm +nopqrs +tuvwxyz +0123456 +789!?@$ +%(){}[]""" +FONT_SAMPLE_SIZES: list[int] = [10,12,15] # TODO: Turn this whitelist into a user-configurable blacklist. IMAGE_TYPES: list[str] = [ diff --git a/tagstudio/src/qt/widgets/thumb_renderer.py b/tagstudio/src/qt/widgets/thumb_renderer.py index f088e1442..612cbe468 100644 --- a/tagstudio/src/qt/widgets/thumb_renderer.py +++ b/tagstudio/src/qt/widgets/thumb_renderer.py @@ -30,6 +30,7 @@ IMAGE_TYPES, RAW_IMAGE_TYPES, FONT_SAMPLE_TEXT, + FONT_SAMPLE_SIZES, ) from src.core.utils.encoding import detect_char_encoding @@ -190,9 +191,17 @@ def render( # Fonts ======================================================== elif _filepath.suffix.lower() in FONT_TYPES: bg = Image.new("RGB", (256, 256), color="#1e1e1e") - font = ImageFont.truetype(_filepath, 25) draw = ImageDraw.Draw(bg) - draw.text((16, 16), FONT_SAMPLE_TEXT, font=font) + lines = FONT_SAMPLE_TEXT.split("\n") + lines.sort(key=draw.textlength) + longest_line = lines[-1] + padding = 2 + x_offset = 0 + for fontsize in FONT_SAMPLE_SIZES: + font = ImageFont.truetype(_filepath,size=fontsize) + text_box_width = draw.textlength(longest_line, font=font) + draw.text((16+x_offset, 16), FONT_SAMPLE_TEXT, font=font) + x_offset += text_box_width+padding image = bg # 3D =========================================================== # elif extension == 'stl': From 81d44f6c17081274bcd1348e5b0aa35c13187824 Mon Sep 17 00:00:00 2001 From: Thesacraft Date: Tue, 2 Jul 2024 14:56:51 +0200 Subject: [PATCH 03/10] Ruff reformat --- tagstudio/src/qt/widgets/thumb_renderer.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tagstudio/src/qt/widgets/thumb_renderer.py b/tagstudio/src/qt/widgets/thumb_renderer.py index 612cbe468..20a0f7d41 100644 --- a/tagstudio/src/qt/widgets/thumb_renderer.py +++ b/tagstudio/src/qt/widgets/thumb_renderer.py @@ -198,10 +198,10 @@ def render( padding = 2 x_offset = 0 for fontsize in FONT_SAMPLE_SIZES: - font = ImageFont.truetype(_filepath,size=fontsize) + font = ImageFont.truetype(_filepath, size=fontsize) text_box_width = draw.textlength(longest_line, font=font) - draw.text((16+x_offset, 16), FONT_SAMPLE_TEXT, font=font) - x_offset += text_box_width+padding + draw.text((16 + x_offset, 16), FONT_SAMPLE_TEXT, font=font) + x_offset += text_box_width + padding image = bg # 3D =========================================================== # elif extension == 'stl': From da7983b79c20b39c588db4eb9edfad9ed44be8e6 Mon Sep 17 00:00:00 2001 From: Thesacraft Date: Tue, 2 Jul 2024 15:01:42 +0200 Subject: [PATCH 04/10] Ruff reformat --- tagstudio/src/core/constants.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tagstudio/src/core/constants.py b/tagstudio/src/core/constants.py index e4b12eb80..4d2f33dbb 100644 --- a/tagstudio/src/core/constants.py +++ b/tagstudio/src/core/constants.py @@ -18,7 +18,7 @@ 0123456 789!?@$ %(){}[]""" -FONT_SAMPLE_SIZES: list[int] = [10,12,15] +FONT_SAMPLE_SIZES: list[int] = [10, 12, 15] # TODO: Turn this whitelist into a user-configurable blacklist. IMAGE_TYPES: list[str] = [ From 5b11f56e2b6b0252a3bbd94a9a906c9709a68ce6 Mon Sep 17 00:00:00 2001 From: Thesacraft Date: Tue, 2 Jul 2024 15:22:09 +0200 Subject: [PATCH 05/10] Added Metadata to info --- tagstudio/src/qt/widgets/preview_panel.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tagstudio/src/qt/widgets/preview_panel.py b/tagstudio/src/qt/widgets/preview_panel.py index 4096c0d7c..834f7b87a 100644 --- a/tagstudio/src/qt/widgets/preview_panel.py +++ b/tagstudio/src/qt/widgets/preview_panel.py @@ -10,7 +10,7 @@ import cv2 import rawpy -from PIL import Image, UnidentifiedImageError +from PIL import Image, UnidentifiedImageError, ImageFont from PIL.Image import DecompressionBombError from PySide6.QtCore import Signal, Qt, QSize from PySide6.QtGui import QResizeEvent, QAction @@ -30,7 +30,13 @@ from src.core.enums import SettingItems, Theme from src.core.library import Entry, ItemType, Library -from src.core.constants import VIDEO_TYPES, IMAGE_TYPES, RAW_IMAGE_TYPES, TS_FOLDER_NAME +from src.core.constants import ( + VIDEO_TYPES, + IMAGE_TYPES, + RAW_IMAGE_TYPES, + TS_FOLDER_NAME, + FONT_TYPES, +) from src.qt.helpers.file_opener import FileOpenerLabel, FileOpenerHelper, open_file from src.qt.modals.add_field import AddFieldModal from src.qt.widgets.thumb_renderer import ThumbRenderer @@ -559,6 +565,11 @@ def update_widgets(self): self.dimensions_label.setText( f"{filepath.suffix.upper()[1:]} • {format_size(filepath.stat().st_size)}\n{image.width} x {image.height} px" ) + elif filepath.suffix.lower() in FONT_TYPES: + font = ImageFont.truetype(filepath) + self.dimensions_label.setText( + f"{filepath.suffix.upper()[1:]} • {font.getname()[0]} : {font.getname()[1]} • {format_size(filepath.stat().st_size)} " + ) else: self.dimensions_label.setText( f"{filepath.suffix.upper()[1:]} • {format_size(filepath.stat().st_size)}" From 5e02fe632f8b8a5337882965cba665d5d04b1e8e Mon Sep 17 00:00:00 2001 From: Thesacraft Date: Wed, 3 Jul 2024 20:15:02 +0200 Subject: [PATCH 06/10] Change the way thumbnails are structured --- tagstudio/src/core/constants.py | 16 ++------ tagstudio/src/qt/helpers/text_wrapper.py | 47 ++++++++++++++++++++++ tagstudio/src/qt/widgets/thumb_renderer.py | 36 +++++++++++------ 3 files changed, 75 insertions(+), 24 deletions(-) create mode 100644 tagstudio/src/qt/helpers/text_wrapper.py diff --git a/tagstudio/src/core/constants.py b/tagstudio/src/core/constants.py index 4d2f33dbb..8afa0fd37 100644 --- a/tagstudio/src/core/constants.py +++ b/tagstudio/src/core/constants.py @@ -7,18 +7,10 @@ COLLAGE_FOLDER_NAME: str = "collages" LIBRARY_FILENAME: str = "ts_library.json" -FONT_SAMPLE_TEXT: str = """ABCDEF -GHIJKLM -NOPQRS -TUVWXYZ -abcdef -ghijklm -nopqrs -tuvwxyz -0123456 -789!?@$ -%(){}[]""" -FONT_SAMPLE_SIZES: list[int] = [10, 12, 15] +FONT_SAMPLE_TEXT: str = ( + """ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!?@$%(){}[]""" +) +FONT_SAMPLE_SIZES: list[int] = [12, 15, 20] # TODO: Turn this whitelist into a user-configurable blacklist. IMAGE_TYPES: list[str] = [ diff --git a/tagstudio/src/qt/helpers/text_wrapper.py b/tagstudio/src/qt/helpers/text_wrapper.py new file mode 100644 index 000000000..dcda1a2f5 --- /dev/null +++ b/tagstudio/src/qt/helpers/text_wrapper.py @@ -0,0 +1,47 @@ +from PIL import Image, ImageDraw, ImageFont + + +def wrap_line( # type: ignore + text: str, + font: ImageFont.ImageFont, + width: int = 256, + draw: ImageDraw.ImageDraw = None, +) -> int: + """ + Takes in a single line and returns the index it should be broken up at but + it only splits one Time + """ + if draw is None: + bg = Image.new("RGB", (width, width), color="#1e1e1e") + draw = ImageDraw.Draw(bg) + if draw.textlength(text, font=font) > 256: + for i in range( + int(len(text) / int(draw.textlength(text, font=font)) * 256), + 0, + -1, + ): + if draw.textlength(text[:i], font=font) < 256: + return i + else: + return -1 + + +def wrap_full_text( + text: str, + font: ImageFont.ImageFont, + width: int = 256, + draw: ImageDraw.ImageDraw = None, +) -> str: + """ + Takes in a string and breaks it up to fit in the canvas given accounts for kerning and font size etc. + """ + lines = [] + i = 0 + last_i = 0 + while wrap_line(text[i:], font=font, width=width, draw=draw) > 0: + i = wrap_line(text[i:], font=font, draw=draw) + last_i + lines.append(text[last_i:i]) + last_i = i + lines.append(text[last_i:]) + text_wrapped = "\n".join(lines) + return text_wrapped diff --git a/tagstudio/src/qt/widgets/thumb_renderer.py b/tagstudio/src/qt/widgets/thumb_renderer.py index 20a0f7d41..684b45cb3 100644 --- a/tagstudio/src/qt/widgets/thumb_renderer.py +++ b/tagstudio/src/qt/widgets/thumb_renderer.py @@ -23,6 +23,7 @@ from PySide6.QtCore import QObject, Signal, QSize from PySide6.QtGui import QPixmap from src.qt.helpers.gradient import four_corner_gradient_background +from src.qt.helpers.text_wrapper import wrap_full_text from src.core.constants import ( PLAINTEXT_TYPES, FONT_TYPES, @@ -190,18 +191,29 @@ def render( image = bg # Fonts ======================================================== elif _filepath.suffix.lower() in FONT_TYPES: - bg = Image.new("RGB", (256, 256), color="#1e1e1e") - draw = ImageDraw.Draw(bg) - lines = FONT_SAMPLE_TEXT.split("\n") - lines.sort(key=draw.textlength) - longest_line = lines[-1] - padding = 2 - x_offset = 0 - for fontsize in FONT_SAMPLE_SIZES: - font = ImageFont.truetype(_filepath, size=fontsize) - text_box_width = draw.textlength(longest_line, font=font) - draw.text((16 + x_offset, 16), FONT_SAMPLE_TEXT, font=font) - x_offset += text_box_width + padding + if gradient: + # handles small thumbnails + bg = Image.new("RGB", (256, 256), color="#1e1e1e") + draw = ImageDraw.Draw(bg) + font = ImageFont.truetype(_filepath, size=170) + draw.text((10, 0), "Aa", font=font) + else: + # handles big thumbnails and renders a sample text in multiple font sizes + bg = Image.new("RGB", (256, 256), color="#1e1e1e") + draw = ImageDraw.Draw(bg) + lines_of_padding = 2 + y_offset = 0 + + for font_size in FONT_SAMPLE_SIZES: + font = ImageFont.truetype(_filepath, size=font_size) + text_wrapped: str = wrap_full_text( + FONT_SAMPLE_TEXT, font=font, draw=draw + ) + draw.multiline_text((0, y_offset), text_wrapped, font=font) + y_offset += ( + len(text_wrapped.split("\n")) + lines_of_padding + ) * draw.textbbox((0, 0), "A", font=font)[-1] + image = bg # 3D =========================================================== # elif extension == 'stl': From f3b17ad2dddf4bd216ef9b9d5c6e0f924690545f Mon Sep 17 00:00:00 2001 From: Thesacraft Date: Wed, 3 Jul 2024 21:06:27 +0200 Subject: [PATCH 07/10] Small performance improvement --- tagstudio/src/qt/helpers/text_wrapper.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tagstudio/src/qt/helpers/text_wrapper.py b/tagstudio/src/qt/helpers/text_wrapper.py index dcda1a2f5..3194cb368 100644 --- a/tagstudio/src/qt/helpers/text_wrapper.py +++ b/tagstudio/src/qt/helpers/text_wrapper.py @@ -15,12 +15,15 @@ def wrap_line( # type: ignore bg = Image.new("RGB", (width, width), color="#1e1e1e") draw = ImageDraw.Draw(bg) if draw.textlength(text, font=font) > 256: + # print(draw.textlength(text, font=font)) for i in range( - int(len(text) / int(draw.textlength(text, font=font)) * 256), + int(len(text) / int(draw.textlength(text, font=font)) * 256) - 2, 0, -1, ): if draw.textlength(text[:i], font=font) < 256: + # print(len(text)) + # print(i) return i else: return -1 From 9eaa9fc21d1633c2d0163a2cc759f155a0594fee Mon Sep 17 00:00:00 2001 From: Thesacraft Date: Wed, 3 Jul 2024 21:48:04 +0200 Subject: [PATCH 08/10] changed Metadata display structure --- tagstudio/src/qt/widgets/preview_panel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tagstudio/src/qt/widgets/preview_panel.py b/tagstudio/src/qt/widgets/preview_panel.py index 834f7b87a..345883bae 100644 --- a/tagstudio/src/qt/widgets/preview_panel.py +++ b/tagstudio/src/qt/widgets/preview_panel.py @@ -568,7 +568,7 @@ def update_widgets(self): elif filepath.suffix.lower() in FONT_TYPES: font = ImageFont.truetype(filepath) self.dimensions_label.setText( - f"{filepath.suffix.upper()[1:]} • {font.getname()[0]} : {font.getname()[1]} • {format_size(filepath.stat().st_size)} " + f"{filepath.suffix.upper()[1:]} • {format_size(filepath.stat().st_size)}\n{font.getname()[0]} : {font.getname()[1]} " ) else: self.dimensions_label.setText( From 9d20c4ce1cf9f2eda1b58443dc59e58e8c5712a4 Mon Sep 17 00:00:00 2001 From: Thesacraft Date: Thu, 4 Jul 2024 19:09:04 +0200 Subject: [PATCH 09/10] added copyright notice to added file --- tagstudio/src/qt/helpers/text_wrapper.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tagstudio/src/qt/helpers/text_wrapper.py b/tagstudio/src/qt/helpers/text_wrapper.py index 3194cb368..729915d28 100644 --- a/tagstudio/src/qt/helpers/text_wrapper.py +++ b/tagstudio/src/qt/helpers/text_wrapper.py @@ -1,3 +1,7 @@ +# Copyright (C) 2024 Travis Abendshien (CyanVoxel). +# Licensed under the GPL-3.0 License. +# Created for TagStudio: https://github.com/CyanVoxel/TagStudio + from PIL import Image, ImageDraw, ImageFont From 2e0a4007c75203c889419fdd6d4b3befe36ffe4c Mon Sep 17 00:00:00 2001 From: Travis Abendshien Date: Fri, 19 Jul 2024 05:53:12 -0700 Subject: [PATCH 10/10] fix(ui): dynamically scale font previews; add .woff2, .ttc --- tagstudio/src/core/constants.py | 4 ++-- tagstudio/src/qt/helpers/text_wrapper.py | 11 ++++------- tagstudio/src/qt/widgets/preview_panel.py | 2 +- tagstudio/src/qt/widgets/thumb_renderer.py | 17 ++++++++++++----- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/tagstudio/src/core/constants.py b/tagstudio/src/core/constants.py index 8afa0fd37..55d7d3889 100644 --- a/tagstudio/src/core/constants.py +++ b/tagstudio/src/core/constants.py @@ -10,7 +10,7 @@ FONT_SAMPLE_TEXT: str = ( """ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!?@$%(){}[]""" ) -FONT_SAMPLE_SIZES: list[int] = [12, 15, 20] +FONT_SAMPLE_SIZES: list[int] = [10, 15, 20] # TODO: Turn this whitelist into a user-configurable blacklist. IMAGE_TYPES: list[str] = [ @@ -112,7 +112,7 @@ ] PROGRAM_TYPES: list[str] = [".exe", ".app"] SHORTCUT_TYPES: list[str] = [".lnk", ".desktop", ".url"] -FONT_TYPES: list[str] = [".ttf", ".otf", ".woff"] +FONT_TYPES: list[str] = [".ttf", ".otf", ".woff", ".woff2", ".ttc"] ALL_FILE_TYPES: list[str] = ( IMAGE_TYPES diff --git a/tagstudio/src/qt/helpers/text_wrapper.py b/tagstudio/src/qt/helpers/text_wrapper.py index 729915d28..64bd4616d 100644 --- a/tagstudio/src/qt/helpers/text_wrapper.py +++ b/tagstudio/src/qt/helpers/text_wrapper.py @@ -18,16 +18,13 @@ def wrap_line( # type: ignore if draw is None: bg = Image.new("RGB", (width, width), color="#1e1e1e") draw = ImageDraw.Draw(bg) - if draw.textlength(text, font=font) > 256: - # print(draw.textlength(text, font=font)) + if draw.textlength(text, font=font) > width: for i in range( - int(len(text) / int(draw.textlength(text, font=font)) * 256) - 2, + int(len(text) / int(draw.textlength(text, font=font)) * width) - 2, 0, -1, ): - if draw.textlength(text[:i], font=font) < 256: - # print(len(text)) - # print(i) + if draw.textlength(text[:i], font=font) < width: return i else: return -1 @@ -46,7 +43,7 @@ def wrap_full_text( i = 0 last_i = 0 while wrap_line(text[i:], font=font, width=width, draw=draw) > 0: - i = wrap_line(text[i:], font=font, draw=draw) + last_i + i = wrap_line(text[i:], font=font, width=width, draw=draw) + last_i lines.append(text[last_i:i]) last_i = i lines.append(text[last_i:]) diff --git a/tagstudio/src/qt/widgets/preview_panel.py b/tagstudio/src/qt/widgets/preview_panel.py index 345883bae..6e51fb0be 100644 --- a/tagstudio/src/qt/widgets/preview_panel.py +++ b/tagstudio/src/qt/widgets/preview_panel.py @@ -568,7 +568,7 @@ def update_widgets(self): elif filepath.suffix.lower() in FONT_TYPES: font = ImageFont.truetype(filepath) self.dimensions_label.setText( - f"{filepath.suffix.upper()[1:]} • {format_size(filepath.stat().st_size)}\n{font.getname()[0]} : {font.getname()[1]} " + f"{filepath.suffix.upper()[1:]} • {format_size(filepath.stat().st_size)}\n{font.getname()[0]} ({font.getname()[1]}) " ) else: self.dimensions_label.setText( diff --git a/tagstudio/src/qt/widgets/thumb_renderer.py b/tagstudio/src/qt/widgets/thumb_renderer.py index 684b45cb3..b008c9fa7 100644 --- a/tagstudio/src/qt/widgets/thumb_renderer.py +++ b/tagstudio/src/qt/widgets/thumb_renderer.py @@ -191,23 +191,30 @@ def render( image = bg # Fonts ======================================================== elif _filepath.suffix.lower() in FONT_TYPES: + # Scale the sample font sizes to the preview image + # resolution,assuming the sizes are tuned for 256px. + scaled_sizes: list[int] = [ + math.floor(x * (adj_size / 256)) for x in FONT_SAMPLE_SIZES + ] if gradient: # handles small thumbnails - bg = Image.new("RGB", (256, 256), color="#1e1e1e") + bg = Image.new("RGB", (adj_size, adj_size), color="#1e1e1e") draw = ImageDraw.Draw(bg) - font = ImageFont.truetype(_filepath, size=170) + font = ImageFont.truetype( + _filepath, size=math.ceil(adj_size * 0.65) + ) draw.text((10, 0), "Aa", font=font) else: # handles big thumbnails and renders a sample text in multiple font sizes - bg = Image.new("RGB", (256, 256), color="#1e1e1e") + bg = Image.new("RGB", (adj_size, adj_size), color="#1e1e1e") draw = ImageDraw.Draw(bg) lines_of_padding = 2 y_offset = 0 - for font_size in FONT_SAMPLE_SIZES: + for font_size in scaled_sizes: font = ImageFont.truetype(_filepath, size=font_size) text_wrapped: str = wrap_full_text( - FONT_SAMPLE_TEXT, font=font, draw=draw + FONT_SAMPLE_TEXT, font=font, width=adj_size, draw=draw ) draw.multiline_text((0, y_offset), text_wrapped, font=font) y_offset += (