File size: 1,299 Bytes
1dc4501
 
 
3de7286
1dc4501
3de7286
6329a16
3de7286
a184f51
 
3de7286
 
 
ac64ec0
 
a184f51
 
 
 
 
 
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
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(svgwrite.image.Image(href=background, size=(f"{card_width}px", f"{card_height}px")))
    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.decode("utf-8")
        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()