From 994303ade4650555b9c5a565bd4a33e389a91907 Mon Sep 17 00:00:00 2001 From: Mr Finchum Date: Mon, 29 Sep 2025 09:38:23 +0200 Subject: [PATCH] Fix: fixed watermark not working on grayscale images. --- CHANGELOG.md | 7 ++++++- src/optima35/image_handler.py | 22 +++++++++++++++------- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6679ae2..d3720b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # Changelog +## 1.1.x -## 1.1.x: Migration (25.04.11) +### 1.1.4: Bugfix watermark (25.09.29) +- Added a check to ensure watermarks can be added to grayscale images. +- Previously, attempting to add a watermark to a grayscale image would crash the program. + +### 1.1.1-3: Migration (25.04.11) - Migrated from GitLab to my forgejo instance for development. --- diff --git a/src/optima35/image_handler.py b/src/optima35/image_handler.py index 590cede..bd95738 100644 --- a/src/optima35/image_handler.py +++ b/src/optima35/image_handler.py @@ -55,13 +55,21 @@ class ImageProcessor: x = imagewidth - textwidth - margin y = imageheight - textheight - margin - # thin border - drawer.text((x-1, y), text, font = font, fill = (64, 64, 64)) - drawer.text((x+1, y), text, font = font, fill = (64, 64, 64)) - drawer.text((x, y-1), text, font = font, fill = (64, 64, 64)) - drawer.text((x, y+1), text, font = font, fill = (64, 64, 64)) - # Adding text in the desired color - drawer.text((x, y), text, font = font, fill = (255, 255, 255)) + # Pick colors based on mode, code from ChatGPT (the fix part). + if image.mode == "L": # grayscale + border_color = 64 # dark gray border + text_color = 255 # white + else: # RGB, RGBA, etc. + border_color = (64, 64, 64) + text_color = (255, 255, 255) + + # Draw border (four directions) + drawer.text((x - 1, y), text, font=font, fill=border_color) + drawer.text((x + 1, y), text, font=font, fill=border_color) + drawer.text((x, y - 1), text, font=font, fill=border_color) + drawer.text((x, y + 1), text, font=font, fill=border_color) + # Draw main text + drawer.text((x, y), text, font=font, fill=text_color) return image