Spaces:
Sleeping
Sleeping
Update text_integration.py
Browse files- text_integration.py +21 -8
text_integration.py
CHANGED
|
@@ -3,7 +3,7 @@ import gradio as gr
|
|
| 3 |
import numpy as np
|
| 4 |
import cv2
|
| 5 |
|
| 6 |
-
def add_text_to_image(image, text, text_x, text_y, font_size="80px", font_family="
|
| 7 |
"""Fügt Text mit OpenCV zum Bild hinzu - garantiert skalierbar!"""
|
| 8 |
if image is None or not text:
|
| 9 |
return image
|
|
@@ -32,11 +32,17 @@ def add_text_to_image(image, text, text_x, text_y, font_size="80px", font_family
|
|
| 32 |
}
|
| 33 |
actual_color = color_mapping.get(font_color, (255, 255, 255))
|
| 34 |
|
| 35 |
-
# OpenCV Font
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
thickness = max(2, int(pixel_size / 20))
|
| 38 |
|
| 39 |
-
print(f"OpenCV Text: '{text}' an ({text_x}, {text_y}) - Größe: {font_scale:.2f}, Dicke: {thickness}")
|
| 40 |
|
| 41 |
# Text mit OpenCV hinzufügen
|
| 42 |
cv2.putText(
|
|
@@ -67,7 +73,7 @@ def add_text_to_image(image, text, text_x, text_y, font_size="80px", font_family
|
|
| 67 |
except:
|
| 68 |
return image
|
| 69 |
|
| 70 |
-
def create_text_preview(image, text, text_x, text_y, font_size="80px", font_family="
|
| 71 |
"""Vorschau mit OpenCV"""
|
| 72 |
if image is None:
|
| 73 |
return image
|
|
@@ -101,7 +107,14 @@ def create_text_preview(image, text, text_x, text_y, font_size="80px", font_fami
|
|
| 101 |
}
|
| 102 |
actual_color = color_mapping.get(font_color, (255, 255, 255))
|
| 103 |
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
thickness = max(2, int(pixel_size / 20))
|
| 106 |
|
| 107 |
cv2.putText(
|
|
@@ -115,7 +128,7 @@ def create_text_preview(image, text, text_x, text_y, font_size="80px", font_fami
|
|
| 115 |
cv2.LINE_AA
|
| 116 |
)
|
| 117 |
|
| 118 |
-
print(f"OpenCV Vorschau: Größe {font_scale:.2f}")
|
| 119 |
|
| 120 |
# Zurück zu PIL
|
| 121 |
result_image = cv2.cvtColor(preview, cv2.COLOR_BGR2RGB)
|
|
@@ -168,7 +181,7 @@ def create_text_integration_section_t2i():
|
|
| 168 |
)
|
| 169 |
with gr.Column():
|
| 170 |
font_family_t2i = gr.Dropdown(
|
| 171 |
-
choices=["Standard"],
|
| 172 |
value="Standard",
|
| 173 |
label="Schriftart"
|
| 174 |
)
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
import cv2
|
| 5 |
|
| 6 |
+
def add_text_to_image(image, text, text_x, text_y, font_size="80px", font_family="Standard", font_color="Weiß"):
|
| 7 |
"""Fügt Text mit OpenCV zum Bild hinzu - garantiert skalierbar!"""
|
| 8 |
if image is None or not text:
|
| 9 |
return image
|
|
|
|
| 32 |
}
|
| 33 |
actual_color = color_mapping.get(font_color, (255, 255, 255))
|
| 34 |
|
| 35 |
+
# OpenCV Font basierend auf Auswahl
|
| 36 |
+
font_mapping = {
|
| 37 |
+
"Standard": cv2.FONT_HERSHEY_SIMPLEX,
|
| 38 |
+
"Einfache Handschrift": cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,
|
| 39 |
+
"Verschnörkelte Handschrift": cv2.FONT_HERSHEY_SCRIPT_COMPLEX
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
font = font_mapping.get(font_family, cv2.FONT_HERSHEY_SIMPLEX)
|
| 43 |
thickness = max(2, int(pixel_size / 20))
|
| 44 |
|
| 45 |
+
print(f"OpenCV Text: '{text}' an ({text_x}, {text_y}) - Schrift: {font_family}, Größe: {font_scale:.2f}, Dicke: {thickness}")
|
| 46 |
|
| 47 |
# Text mit OpenCV hinzufügen
|
| 48 |
cv2.putText(
|
|
|
|
| 73 |
except:
|
| 74 |
return image
|
| 75 |
|
| 76 |
+
def create_text_preview(image, text, text_x, text_y, font_size="80px", font_family="Standard", font_color="Weiß"):
|
| 77 |
"""Vorschau mit OpenCV"""
|
| 78 |
if image is None:
|
| 79 |
return image
|
|
|
|
| 107 |
}
|
| 108 |
actual_color = color_mapping.get(font_color, (255, 255, 255))
|
| 109 |
|
| 110 |
+
# OpenCV Font basierend auf Auswahl
|
| 111 |
+
font_mapping = {
|
| 112 |
+
"Standard": cv2.FONT_HERSHEY_SIMPLEX,
|
| 113 |
+
"Einfache Handschrift": cv2.FONT_HERSHEY_SCRIPT_SIMPLEX,
|
| 114 |
+
"Verschnörkelte Handschrift": cv2.FONT_HERSHEY_SCRIPT_COMPLEX
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
font = font_mapping.get(font_family, cv2.FONT_HERSHEY_SIMPLEX)
|
| 118 |
thickness = max(2, int(pixel_size / 20))
|
| 119 |
|
| 120 |
cv2.putText(
|
|
|
|
| 128 |
cv2.LINE_AA
|
| 129 |
)
|
| 130 |
|
| 131 |
+
print(f"OpenCV Vorschau: Schrift {font_family}, Größe {font_scale:.2f}")
|
| 132 |
|
| 133 |
# Zurück zu PIL
|
| 134 |
result_image = cv2.cvtColor(preview, cv2.COLOR_BGR2RGB)
|
|
|
|
| 181 |
)
|
| 182 |
with gr.Column():
|
| 183 |
font_family_t2i = gr.Dropdown(
|
| 184 |
+
choices=["Standard", "Einfache Handschrift", "Verschnörkelte Handschrift"],
|
| 185 |
value="Standard",
|
| 186 |
label="Schriftart"
|
| 187 |
)
|