-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.py
26 lines (19 loc) · 820 Bytes
/
convert.py
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
import cairosvg
from PIL import Image, ImageOps
def convert_svg_to_png(svg_path, png_path, dpi, border_thickness):
# Convert SVG to PNG using cairosvg library
cairosvg.svg2png(url=svg_path, write_to=png_path, dpi=dpi)
# Open the generated PNG image
image = Image.open(png_path)
# Calculate the border size in pixels based on the DPI
border_size = int(border_thickness * dpi / 25.4)
# Add the white border
image_with_border = ImageOps.expand(image, border_size, fill='white')
# Save the modified image
image_with_border.save(png_path)
# Example usage
svg_path = "analysis.svg"
png_path = "output.png"
dpi = 300 # Set the desired DPI here
border_thickness = 50 # Set the desired border thickness in millimeters
convert_svg_to_png(svg_path, png_path, dpi, border_thickness)