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
## 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.
---

View file

@ -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