File size: 1,024 Bytes
1dc4501
 
 
c9a7bd9
 
 
 
 
 
 
 
 
 
 
 
53aff91
c9a7bd9
53aff91
c9a7bd9
 
53aff91
c9a7bd9
53aff91
c9a7bd9
 
 
 
 
 
 
 
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
import streamlit as st
import svgwrite

def apply_circle_mask(image_path):
    # Load image
    image = svgwrite.Drawing('output.svg')
    image.add(image.image(href=image_path, size=("100%", "100%")))
    
    # Add circular mask
    width, height = image.viewbox[2:]
    half_x, half_y = width/2, height/2
    line_color = "white"
    mask = image.defs.add(image.mask(id="bg_wrapper"))
    mask.add(image.circle(center=(half_x, half_y), r=335, fill=line_color, opacity=".4"))
    image.add(image.image(href=image_path, size=("100%", "100%"), mask="url(#bg_wrapper)"))

    return image.tostring()

# Streamlit app
st.title("Circular Image Mask")

uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])

if uploaded_file is not None:
    # Save uploaded image to file
    with open("image.jpg", "wb") as f:
        f.write(uploaded_file.getbuffer())
    
    # Apply circular mask and display result
    output_svg = apply_circle_mask("image.jpg")
    st.image(output_svg, output_format="SVG")