File size: 1,678 Bytes
1dc4501
 
 
3de7286
1dc4501
53aff91
3de7286
6329a16
53aff91
 
 
 
 
 
 
 
 
 
a184f51
 
3de7286
 
 
ac64ec0
 
a184f51
 
 
 
 
 
3de7286
 
b789f53
3de7286
ac64ec0
3de7286
1349f96
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import streamlit as st
import svgwrite
from PIL import Image
from io import BytesIO


def draw_card(card_width, card_height, background):
    dwg = svgwrite.Drawing(size=(f"{card_width}px", f"{card_height}px"))
    dwg.add(dwg.rect((0, 0), (card_width, card_height), rx=10, ry=10, fill=background, stroke="black", stroke_width=2))

    # Create a mask
    mask = dwg.defs.add(dwg.mask(id="bg_wrapper"))
    mask.add(dwg.circle(center=(card_width/2, card_height/2), r=card_width/2, fill="white"))
    mask.add(dwg.image(href=background, size=(card_width, card_height)))

    # Add an image using the mask
    dwg.add(dwg.image(href=background, size=(card_width, card_height), mask="url(#bg_wrapper)"))

    return dwg.tostring()

def main():
    st.set_page_config(page_title="Card Evolution Game", page_icon=":hearts:")
    card_width, card_height = 100, 150
    uploaded_file = st.sidebar.file_uploader("Upload Card Background Image", type=["png", "jpg", "jpeg"])
    if uploaded_file is not None:
        image = Image.open(uploaded_file)
        image = image.resize((card_width, card_height))
        img_bytes = BytesIO()
        image.save(img_bytes, format="PNG")
        img_data = img_bytes.getvalue()
        img_href = "data:image/png;base64," + img_data.hex()
        st.write(f'<img src="{img_href}">', unsafe_allow_html=True)
        card_svg = draw_card(card_width, card_height, img_href)
        svg_content = '<?xml version="1.0" encoding="utf-8" ?>' + card_svg
        st.download_button("Download Card as SVG", svg_content, "card.svg", "text/plain")
    else:
        st.warning("Please upload a card background image")

if __name__ == '__main__':
    main()