Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -38,7 +38,6 @@ def render_plain_text_image(text, font_size, width, height, bg_color, text_color
|
|
38 |
for line in text.split('\n'):
|
39 |
lines.extend(textwrap.wrap(line, width=int(max_width / font_size * 1.8)))
|
40 |
|
41 |
-
# Use getbbox() instead of getsize()
|
42 |
bbox = font.getbbox('Ay')
|
43 |
line_height = bbox[3] - bbox[1]
|
44 |
total_text_height = line_height * len(lines)
|
@@ -46,7 +45,6 @@ def render_plain_text_image(text, font_size, width, height, bg_color, text_color
|
|
46 |
y = (height - total_text_height) // 2
|
47 |
|
48 |
for line in lines:
|
49 |
-
# Use getbbox() to get line width
|
50 |
bbox = font.getbbox(line)
|
51 |
line_width = bbox[2] - bbox[0]
|
52 |
|
@@ -80,7 +78,8 @@ def render_math_image(text, font_size, width, height, bg_color, text_color):
|
|
80 |
plt.close(fig)
|
81 |
|
82 |
buf.seek(0)
|
83 |
-
|
|
|
84 |
|
85 |
def text_to_image(input_text, font_size, width, height, bg_color, text_color, mode, font_name, align, image_format):
|
86 |
if mode == "Plain Text":
|
@@ -89,11 +88,9 @@ def text_to_image(input_text, font_size, width, height, bg_color, text_color, mo
|
|
89 |
img = render_math_image(input_text, font_size, width, height, bg_color, text_color)
|
90 |
else:
|
91 |
return "Invalid mode selected!"
|
92 |
-
|
93 |
-
|
94 |
-
img
|
95 |
-
buf.seek(0)
|
96 |
-
return buf
|
97 |
|
98 |
def handle_file_upload(file, font_size, width, height, bg_color, text_color, mode, font_name, align, image_format):
|
99 |
if file is not None:
|
|
|
38 |
for line in text.split('\n'):
|
39 |
lines.extend(textwrap.wrap(line, width=int(max_width / font_size * 1.8)))
|
40 |
|
|
|
41 |
bbox = font.getbbox('Ay')
|
42 |
line_height = bbox[3] - bbox[1]
|
43 |
total_text_height = line_height * len(lines)
|
|
|
45 |
y = (height - total_text_height) // 2
|
46 |
|
47 |
for line in lines:
|
|
|
48 |
bbox = font.getbbox(line)
|
49 |
line_width = bbox[2] - bbox[0]
|
50 |
|
|
|
78 |
plt.close(fig)
|
79 |
|
80 |
buf.seek(0)
|
81 |
+
img = Image.open(buf)
|
82 |
+
return img
|
83 |
|
84 |
def text_to_image(input_text, font_size, width, height, bg_color, text_color, mode, font_name, align, image_format):
|
85 |
if mode == "Plain Text":
|
|
|
88 |
img = render_math_image(input_text, font_size, width, height, bg_color, text_color)
|
89 |
else:
|
90 |
return "Invalid mode selected!"
|
91 |
+
|
92 |
+
# Return the PIL Image directly instead of BytesIO
|
93 |
+
return img
|
|
|
|
|
94 |
|
95 |
def handle_file_upload(file, font_size, width, height, bg_color, text_color, mode, font_name, align, image_format):
|
96 |
if file is not None:
|