Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -135,9 +135,13 @@ def generate_card():
|
|
| 135 |
|
| 136 |
draw = ImageDraw.Draw(img)
|
| 137 |
|
| 138 |
-
#
|
|
|
|
|
|
|
|
|
|
| 139 |
fonts_loaded = False
|
| 140 |
|
|
|
|
| 141 |
try:
|
| 142 |
# Try to download Google Fonts
|
| 143 |
font_urls = {
|
|
@@ -153,30 +157,40 @@ def generate_card():
|
|
| 153 |
timestamp_font = ImageFont.truetype('roboto_mono.ttf', 32)
|
| 154 |
title_font = ImageFont.truetype('orbitron_bold.ttf', 45)
|
| 155 |
fonts_loaded = True
|
|
|
|
| 156 |
|
| 157 |
except Exception as e:
|
| 158 |
-
print(f"
|
| 159 |
# Fallback to system fonts
|
| 160 |
try:
|
| 161 |
system_fonts = [
|
| 162 |
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
|
|
|
|
| 163 |
"/System/Library/Fonts/Helvetica.ttc",
|
|
|
|
| 164 |
"C:\\Windows\\Fonts\\arial.ttf",
|
|
|
|
| 165 |
"arial.ttf"
|
| 166 |
]
|
| 167 |
|
| 168 |
for font_path in system_fonts:
|
| 169 |
if os.path.exists(font_path):
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
# Enhanced color scheme
|
| 182 |
primary_color = (0, 255, 136) # Bright green
|
|
|
|
| 135 |
|
| 136 |
draw = ImageDraw.Draw(img)
|
| 137 |
|
| 138 |
+
# Initialize fonts with defaults first
|
| 139 |
+
code_font = ImageFont.load_default()
|
| 140 |
+
timestamp_font = ImageFont.load_default()
|
| 141 |
+
title_font = ImageFont.load_default()
|
| 142 |
fonts_loaded = False
|
| 143 |
|
| 144 |
+
# Try to load premium fonts
|
| 145 |
try:
|
| 146 |
# Try to download Google Fonts
|
| 147 |
font_urls = {
|
|
|
|
| 157 |
timestamp_font = ImageFont.truetype('roboto_mono.ttf', 32)
|
| 158 |
title_font = ImageFont.truetype('orbitron_bold.ttf', 45)
|
| 159 |
fonts_loaded = True
|
| 160 |
+
print("✅ Premium fonts loaded successfully!")
|
| 161 |
|
| 162 |
except Exception as e:
|
| 163 |
+
print(f"⚠️ Premium font loading failed: {e}")
|
| 164 |
# Fallback to system fonts
|
| 165 |
try:
|
| 166 |
system_fonts = [
|
| 167 |
"/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf",
|
| 168 |
+
"/usr/share/fonts/truetype/liberation/LiberationSans-Bold.ttf",
|
| 169 |
"/System/Library/Fonts/Helvetica.ttc",
|
| 170 |
+
"/System/Library/Fonts/Arial.ttf",
|
| 171 |
"C:\\Windows\\Fonts\\arial.ttf",
|
| 172 |
+
"C:\\Windows\\Fonts\\calibri.ttf",
|
| 173 |
"arial.ttf"
|
| 174 |
]
|
| 175 |
|
| 176 |
for font_path in system_fonts:
|
| 177 |
if os.path.exists(font_path):
|
| 178 |
+
try:
|
| 179 |
+
code_font = ImageFont.truetype(font_path, 85)
|
| 180 |
+
timestamp_font = ImageFont.truetype(font_path, 32)
|
| 181 |
+
title_font = ImageFont.truetype(font_path, 45)
|
| 182 |
+
fonts_loaded = True
|
| 183 |
+
print(f"✅ System font loaded: {font_path}")
|
| 184 |
+
break
|
| 185 |
+
except Exception as font_error:
|
| 186 |
+
print(f"❌ Failed to load {font_path}: {font_error}")
|
| 187 |
+
continue
|
| 188 |
+
|
| 189 |
+
except Exception as system_error:
|
| 190 |
+
print(f"⚠️ System font loading failed: {system_error}")
|
| 191 |
+
print("📝 Using default fonts")
|
| 192 |
+
|
| 193 |
+
print(f"🎨 Fonts loaded: {'Premium' if fonts_loaded else 'Default'}")
|
| 194 |
|
| 195 |
# Enhanced color scheme
|
| 196 |
primary_color = (0, 255, 136) # Bright green
|