Fix: fixed watermark not working on grayscale images.
This commit is contained in:
parent
daba110805
commit
994303ade4
2 changed files with 21 additions and 8 deletions
|
|
@ -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.
|
||||
|
||||
---
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue