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