Update app.py
Browse files
app.py
CHANGED
|
@@ -96,20 +96,12 @@ class TelegramChatGenerator:
|
|
| 96 |
if max_radius < 1:
|
| 97 |
max_radius = 1
|
| 98 |
|
| 99 |
-
# Draw
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
shadow_color = (0, 0, 0,
|
| 104 |
-
|
| 105 |
-
# Create shadow layer
|
| 106 |
-
shadow_layer = Image.new('RGBA', draw.im.size, (0, 0, 0, 0))
|
| 107 |
-
shadow_draw = ImageDraw.Draw(shadow_layer)
|
| 108 |
-
self.draw_rounded_rectangle(shadow_draw, shadow_coords, max_radius, shadow_color)
|
| 109 |
-
|
| 110 |
-
# Blur the shadow
|
| 111 |
-
shadow_layer = shadow_layer.filter(ImageFilter.GaussianBlur(radius=1))
|
| 112 |
-
draw.im.paste(shadow_layer, (0, 0), shadow_layer)
|
| 113 |
|
| 114 |
# Draw main bubble
|
| 115 |
self.draw_rounded_rectangle(draw, coords, max_radius, fill)
|
|
@@ -138,22 +130,30 @@ class TelegramChatGenerator:
|
|
| 138 |
draw.rectangle([x1, y1, x2, y2], fill=fill)
|
| 139 |
return
|
| 140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 141 |
# Main rectangles (only if they have positive dimensions)
|
| 142 |
if width > 2 * max_radius:
|
| 143 |
-
draw.rectangle([x1 + max_radius, y1, x2 - max_radius, y2], fill=
|
| 144 |
if height > 2 * max_radius:
|
| 145 |
-
draw.rectangle([x1, y1 + max_radius, x2, y2 - max_radius], fill=
|
| 146 |
|
| 147 |
# Corner circles (only if there's space for them)
|
| 148 |
if width >= 2 * max_radius and height >= 2 * max_radius:
|
| 149 |
# Top-left
|
| 150 |
-
draw.ellipse([x1, y1, x1 + 2 * max_radius, y1 + 2 * max_radius], fill=
|
| 151 |
# Top-right
|
| 152 |
-
draw.ellipse([x2 - 2 * max_radius, y1, x2, y1 + 2 * max_radius], fill=
|
| 153 |
# Bottom-left
|
| 154 |
-
draw.ellipse([x1, y2 - 2 * max_radius, x1 + 2 * max_radius, y2], fill=
|
| 155 |
# Bottom-right
|
| 156 |
-
draw.ellipse([x2 - 2 * max_radius, y2 - 2 * max_radius, x2, y2], fill=
|
| 157 |
|
| 158 |
def get_text_dimensions(self, text, font):
|
| 159 |
"""Get accurate text dimensions"""
|
|
|
|
| 96 |
if max_radius < 1:
|
| 97 |
max_radius = 1
|
| 98 |
|
| 99 |
+
# Draw simple shadow first
|
| 100 |
+
if shadow_offset > 0:
|
| 101 |
+
shadow_coords = (x1 + shadow_offset, y1 + shadow_offset,
|
| 102 |
+
x2 + shadow_offset, y2 + shadow_offset)
|
| 103 |
+
shadow_color = (0, 0, 0, 60) # Semi-transparent black
|
| 104 |
+
self.draw_rounded_rectangle(draw, shadow_coords, max_radius, shadow_color)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
# Draw main bubble
|
| 107 |
self.draw_rounded_rectangle(draw, coords, max_radius, fill)
|
|
|
|
| 130 |
draw.rectangle([x1, y1, x2, y2], fill=fill)
|
| 131 |
return
|
| 132 |
|
| 133 |
+
# Handle both RGB and RGBA fills
|
| 134 |
+
if len(fill) == 3:
|
| 135 |
+
# RGB - add full opacity
|
| 136 |
+
fill_color = fill + (255,)
|
| 137 |
+
else:
|
| 138 |
+
# RGBA - use as is
|
| 139 |
+
fill_color = fill
|
| 140 |
+
|
| 141 |
# Main rectangles (only if they have positive dimensions)
|
| 142 |
if width > 2 * max_radius:
|
| 143 |
+
draw.rectangle([x1 + max_radius, y1, x2 - max_radius, y2], fill=fill_color)
|
| 144 |
if height > 2 * max_radius:
|
| 145 |
+
draw.rectangle([x1, y1 + max_radius, x2, y2 - max_radius], fill=fill_color)
|
| 146 |
|
| 147 |
# Corner circles (only if there's space for them)
|
| 148 |
if width >= 2 * max_radius and height >= 2 * max_radius:
|
| 149 |
# Top-left
|
| 150 |
+
draw.ellipse([x1, y1, x1 + 2 * max_radius, y1 + 2 * max_radius], fill=fill_color)
|
| 151 |
# Top-right
|
| 152 |
+
draw.ellipse([x2 - 2 * max_radius, y1, x2, y1 + 2 * max_radius], fill=fill_color)
|
| 153 |
# Bottom-left
|
| 154 |
+
draw.ellipse([x1, y2 - 2 * max_radius, x1 + 2 * max_radius, y2], fill=fill_color)
|
| 155 |
# Bottom-right
|
| 156 |
+
draw.ellipse([x2 - 2 * max_radius, y2 - 2 * max_radius, x2, y2], fill=fill_color)
|
| 157 |
|
| 158 |
def get_text_dimensions(self, text, font):
|
| 159 |
"""Get accurate text dimensions"""
|