Spaces:
Runtime error
Runtime error
Update process_energy.py
Browse files- process_energy.py +10 -4
process_energy.py
CHANGED
@@ -185,11 +185,17 @@ def create_affirmation_frame(text, width=640, height=480, duration=5):
|
|
185 |
font = ImageFont.truetype(font_path, font_size)
|
186 |
except IOError:
|
187 |
font = ImageFont.load_default()
|
|
|
|
|
|
|
|
|
188 |
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
|
|
|
|
193 |
|
194 |
return frame
|
195 |
|
|
|
185 |
font = ImageFont.truetype(font_path, font_size)
|
186 |
except IOError:
|
187 |
font = ImageFont.load_default()
|
188 |
+
|
189 |
+
lines = text.split('\n')
|
190 |
+
total_height = sum([draw.textbbox((0, 0), line, font=font)[3] - draw.textbbox((0, 0), line, font=font)[1] for line in lines])
|
191 |
+
y_text = (height - total_height) // 2
|
192 |
|
193 |
+
for line in lines:
|
194 |
+
bbox = draw.textbbox((0, 0), line, font=font)
|
195 |
+
width_text = bbox[2] - bbox[0]
|
196 |
+
height_text = bbox[3] - bbox[1]
|
197 |
+
draw.text(((width - width_text) / 2, y_text), line, font=font, fill="white")
|
198 |
+
y_text += height_text
|
199 |
|
200 |
return frame
|
201 |
|