Spaces:
Sleeping
Sleeping
Update text_integration.py
Browse files- text_integration.py +9 -0
text_integration.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from PIL import Image, ImageDraw, ImageFont
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
|
| 4 |
def add_text_to_image(image, text, text_x, text_y, font_size=36, font_color="#FFFFFF"):
|
| 5 |
"""Fügt Text mit PIL zum Bild hinzu"""
|
|
@@ -7,6 +8,10 @@ def add_text_to_image(image, text, text_x, text_y, font_size=36, font_color="#FF
|
|
| 7 |
return image
|
| 8 |
|
| 9 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
image_with_text = image.copy()
|
| 11 |
draw = ImageDraw.Draw(image_with_text)
|
| 12 |
|
|
@@ -29,6 +34,10 @@ def create_text_preview(image, text, text_x, text_y, font_size=36, font_color="#
|
|
| 29 |
return image
|
| 30 |
|
| 31 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
preview = image.copy()
|
| 33 |
draw = ImageDraw.Draw(preview)
|
| 34 |
|
|
|
|
| 1 |
from PIL import Image, ImageDraw, ImageFont
|
| 2 |
import gradio as gr
|
| 3 |
+
import numpy as np
|
| 4 |
|
| 5 |
def add_text_to_image(image, text, text_x, text_y, font_size=36, font_color="#FFFFFF"):
|
| 6 |
"""Fügt Text mit PIL zum Bild hinzu"""
|
|
|
|
| 8 |
return image
|
| 9 |
|
| 10 |
try:
|
| 11 |
+
# Konvertiere numpy array zu PIL Image falls nötig
|
| 12 |
+
if isinstance(image, np.ndarray):
|
| 13 |
+
image = Image.fromarray(image)
|
| 14 |
+
|
| 15 |
image_with_text = image.copy()
|
| 16 |
draw = ImageDraw.Draw(image_with_text)
|
| 17 |
|
|
|
|
| 34 |
return image
|
| 35 |
|
| 36 |
try:
|
| 37 |
+
# Konvertiere numpy array zu PIL Image falls nötig
|
| 38 |
+
if isinstance(image, np.ndarray):
|
| 39 |
+
image = Image.fromarray(image)
|
| 40 |
+
|
| 41 |
preview = image.copy()
|
| 42 |
draw = ImageDraw.Draw(preview)
|
| 43 |
|