Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -14,57 +14,6 @@ LEVELS = {"level 1": ["common", "uncommon", "rare"],
|
|
14 |
"level 2": ["epic", "legendary", "mythic"],
|
15 |
"level 3": ["godlike"]}
|
16 |
|
17 |
-
def draw_cardold(background, suit, value, level, card_width, card_height):
|
18 |
-
dwg = svgwrite.Drawing(size=(f"{card_width}px", f"{card_height}px"))
|
19 |
-
dwg.add(dwg.rect((0, 0), (card_width, card_height), rx=10, ry=10, fill="white", stroke="black", stroke_width=2))
|
20 |
-
if background:
|
21 |
-
img = svgwrite.image.Image(href=background, size=(f"{card_width}px", f"{card_height}px"))
|
22 |
-
dwg.add(img)
|
23 |
-
suit = svgwrite.text.Text(suit.upper(), insert=(5, 15), fill="black", font_size="16px", font_weight="bold")
|
24 |
-
dwg.add(suit)
|
25 |
-
value = svgwrite.text.Text(value, insert=(5, card_height - 10), fill="black", font_size="16px", font_weight="bold")
|
26 |
-
dwg.add(value)
|
27 |
-
level = svgwrite.text.Text(level.upper(), insert=(card_width - 50, card_height - 10), fill="black", font_size="12px", font_weight="bold")
|
28 |
-
dwg.add(level)
|
29 |
-
svg_string = dwg.tostring()
|
30 |
-
return svg_string
|
31 |
-
|
32 |
-
def draw_card_old2(background, suit, value, level, card_width, card_height):
|
33 |
-
dwg = svgwrite.Drawing(size=(f"{card_width}px", f"{card_height}px"))
|
34 |
-
dwg.add(dwg.rect((0, 0), (card_width, card_height), rx=10, ry=10, fill="white", stroke="black", stroke_width=2))
|
35 |
-
|
36 |
-
# Add background image, if provided
|
37 |
-
if background:
|
38 |
-
# Determine file type and open image
|
39 |
-
image_file = urllib.request.urlopen(background)
|
40 |
-
file_type = background.split(".")[-1].lower()
|
41 |
-
if file_type == "png":
|
42 |
-
image = Image.open(image_file)
|
43 |
-
elif file_type == "jpg" or file_type == "jpeg":
|
44 |
-
image = Image.open(image_file).convert("RGBA")
|
45 |
-
else:
|
46 |
-
st.warning("Unsupported file type. Please upload a PNG or JPEG image.")
|
47 |
-
return ""
|
48 |
-
|
49 |
-
# Resize and add image to SVG
|
50 |
-
image = image.resize((card_width, card_height))
|
51 |
-
image.save("background.png")
|
52 |
-
img = svgwrite.image.Image(href="background.png", size=(f"{card_width}px", f"{card_height}px"))
|
53 |
-
dwg.add(img)
|
54 |
-
|
55 |
-
# Add suit and value labels
|
56 |
-
suit = svgwrite.text.Text(suit.upper(), insert=(5, 15), fill="black", font_size="16px", font_weight="bold")
|
57 |
-
dwg.add(suit)
|
58 |
-
value = svgwrite.text.Text(value, insert=(5, card_height - 10), fill="black", font_size="16px", font_weight="bold")
|
59 |
-
dwg.add(value)
|
60 |
-
|
61 |
-
# Add level label
|
62 |
-
level = svgwrite.text.Text(level.upper(), insert=(card_width - 50, card_height - 10), fill="black", font_size="12px", font_weight="bold")
|
63 |
-
dwg.add(level)
|
64 |
-
|
65 |
-
svg_string = dwg.tostring()
|
66 |
-
return svg_string
|
67 |
-
|
68 |
def draw_card(background, suit, value, level, card_width, card_height):
|
69 |
print(f"Background image: {background}")
|
70 |
dwg = svgwrite.Drawing(size=(f"{card_width}px", f"{card_height}px"))
|
|
|
14 |
"level 2": ["epic", "legendary", "mythic"],
|
15 |
"level 3": ["godlike"]}
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
def draw_card(background, suit, value, level, card_width, card_height):
|
18 |
print(f"Background image: {background}")
|
19 |
dwg = svgwrite.Drawing(size=(f"{card_width}px", f"{card_height}px"))
|