dotfiles/awesome/icons/svgs/svg_to_png.py

20 lines
517 B
Python
Raw Permalink Normal View History

#!/usr/bin/env python3
import pathlib
from cairosvg import svg2png
from PIL import Image, ImageOps
2023-01-30 14:09:45 +00:00
SIZE = 100
part_size = SIZE//5
for svg in pathlib.Path('.').glob('*.svg'):
print(f'Converting {svg.name}...', end='')
png = svg.with_suffix('.png')
2023-01-30 14:09:45 +00:00
svg2png(url=str(svg), write_to=str(png), output_width=part_size*3, output_height=part_size*3)
with Image.open(png) as img:
img.load()
2023-01-30 14:09:45 +00:00
border_img = ImageOps.expand(img, part_size, (0, 0, 0, 0))
border_img.save(png)
print(' Done')