boost sign image thickness and contrast
This commit is contained in:
parent
c00060af2d
commit
a19353f869
1 changed files with 19 additions and 3 deletions
22
main.py
22
main.py
|
@ -5,7 +5,7 @@ from random import choice
|
|||
from sys import argv
|
||||
from urllib.request import urlretrieve
|
||||
|
||||
from PIL import Image, ImageDraw, ImageFont
|
||||
from PIL import Image, ImageDraw, ImageEnhance, ImageFilter, ImageFont
|
||||
|
||||
zodiac_signs = [
|
||||
"Belier",
|
||||
|
@ -41,6 +41,23 @@ def get_path(image: str):
|
|||
return join(image_dir, f"{image.lower()}.png")
|
||||
|
||||
|
||||
def get_sign_image(image: str):
|
||||
"""Get sign image"""
|
||||
sign_image = Image.open(get_path(image)).convert("RGBA")
|
||||
|
||||
# Add thickness
|
||||
alpha = sign_image.split()[3]
|
||||
bold_mask = alpha.filter(ImageFilter.MaxFilter())
|
||||
sign_image.putalpha(bold_mask)
|
||||
|
||||
# Add contrast
|
||||
enhancer = ImageEnhance.Contrast(sign_image)
|
||||
enhanced_image = enhancer.enhance(2.0)
|
||||
|
||||
enhanced_image.thumbnail((100, 105))
|
||||
return enhanced_image
|
||||
|
||||
|
||||
def create_horoscope_image(horoscope: dict[str, dict[str, str]]):
|
||||
"""Generate horoscope images"""
|
||||
img_width, img_height = 1200, 425
|
||||
|
@ -54,8 +71,7 @@ def create_horoscope_image(horoscope: dict[str, dict[str, str]]):
|
|||
|
||||
x, y = 10, 10
|
||||
for sign, prediction in horoscope.items():
|
||||
sign_image = Image.open(get_path(sign)).convert("RGBA")
|
||||
sign_image.thumbnail((100, 105))
|
||||
sign_image = get_sign_image(sign)
|
||||
image.paste(sign_image, (x + 20, y), sign_image)
|
||||
|
||||
# Sign text
|
||||
|
|
Loading…
Reference in a new issue