|
import cairosvg |
|
import gradio as gr |
|
from PIL import Image |
|
import os |
|
|
|
def show(svg_input): |
|
|
|
output_path = "./test.png" |
|
cairosvg.svg2png(bytestring=svg_input.encode('utf-8'), write_to=output_path) |
|
|
|
|
|
png_image = Image.open(output_path) |
|
return png_image, output_path |
|
|
|
with gr.Blocks() as bl: |
|
gr.Markdown("# SVG to PNG Converter") |
|
|
|
with gr.Row(): |
|
with gr.Column(): |
|
svg_input = gr.Textbox(label="SVG URL or Code", placeholder="Enter SVG URL or paste SVG code here") |
|
convert_btn = gr.Button("Convert") |
|
|
|
with gr.Column(): |
|
png_output = gr.Image(type='pil', label="Converted PNG") |
|
download_btn = gr.File(label="Download PNG") |
|
|
|
|
|
convert_btn.click( |
|
fn=show, |
|
inputs=svg_input, |
|
outputs=[png_output, download_btn] |
|
) |
|
|
|
bl.launch() |