Update weather_icons.py

remove alpha threshold in weather_icons
This commit is contained in:
Chuck
2025-04-17 21:36:09 -05:00
parent 0fa933c596
commit e6d400281c

View File

@@ -163,12 +163,15 @@ class WeatherIcons:
# to remove faint anti-aliasing pixels when pasting on black bg. # to remove faint anti-aliasing pixels when pasting on black bg.
# Pixels with alpha > 200 will be fully opaque, others fully transparent. # Pixels with alpha > 200 will be fully opaque, others fully transparent.
try: try:
alpha = icon_to_draw.getchannel('A') # alpha = icon_to_draw.getchannel('A')
# Apply threshold: lambda function returns 255 if input > 200, else 0 # # Apply threshold: lambda function returns 255 if input > 200, else 0
threshold_mask = alpha.point(lambda p: 255 if p > 200 else 0) # threshold_mask = alpha.point(lambda p: 255 if p > 200 else 0)
# Paste the icon using the thresholded mask # Paste the icon using the thresholded mask
image.paste(icon_to_draw, (x, y), threshold_mask) # image.paste(icon_to_draw, (x, y), threshold_mask)
# Paste the icon directly with its original alpha channel
image.paste(icon_to_draw, (x, y), icon_to_draw)
except Exception as e: except Exception as e:
print(f"Error processing or pasting icon for condition '{condition}' at ({x},{y}): {e}") print(f"Error processing or pasting icon for condition '{condition}' at ({x},{y}): {e}")
# Fallback or alternative handling if needed # Fallback or alternative handling if needed