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'', unsafe_allow_html=True) card_svg = draw_card(card_width, card_height, img_href) svg_content = '' + 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()