Fix: fixed watermark not working on grayscale images.
All checks were successful
ci/woodpecker/pr/woodpecker_ci Pipeline was successful
ci/woodpecker/pull_request_closed/woodpecker_ci Pipeline was successful
ci/woodpecker/push/woodpecker_ci Pipeline was successful
ci/woodpecker/tag/woodpecker_ci Pipeline was successful

This commit is contained in:
Mr Finchum 2025-09-29 09:38:23 +02:00
parent daba110805
commit 994303ade4
Signed by: CodeByMrFinchum
GPG key ID: C06071E8082FFA0B
2 changed files with 21 additions and 8 deletions

View file

@ -1,6 +1,11 @@
# Changelog # 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. - Migrated from GitLab to my forgejo instance for development.
--- ---

View file

@ -55,13 +55,21 @@ class ImageProcessor:
x = imagewidth - textwidth - margin x = imagewidth - textwidth - margin
y = imageheight - textheight - margin y = imageheight - textheight - margin
# thin border # Pick colors based on mode, code from ChatGPT (the fix part).
drawer.text((x-1, y), text, font = font, fill = (64, 64, 64)) if image.mode == "L": # grayscale
drawer.text((x+1, y), text, font = font, fill = (64, 64, 64)) border_color = 64 # dark gray border
drawer.text((x, y-1), text, font = font, fill = (64, 64, 64)) text_color = 255 # white
drawer.text((x, y+1), text, font = font, fill = (64, 64, 64)) else: # RGB, RGBA, etc.
# Adding text in the desired color border_color = (64, 64, 64)
drawer.text((x, y), text, font = font, fill = (255, 255, 255)) 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 return image