From 0ee3e39c3cb285c4d4790751fd1d8e281a5d9822 Mon Sep 17 00:00:00 2001 From: julius Date: Sun, 27 Oct 2024 19:28:02 +0100 Subject: [PATCH] save as different image formats (pyvips) --- speckles.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/speckles.py b/speckles.py index a53a723..de3b31f 100644 --- a/speckles.py +++ b/speckles.py @@ -1,5 +1,6 @@ import itertools from pathlib import Path +import pyvips import logging from perlin import CoordsGenerator import svg @@ -253,8 +254,12 @@ def make_wallpaper( ) content = svg.SVG(width=x, height=y, elements=elements) - with open(filename, "wt") as f: - f.write(content.as_str()) + if Path(filename).suffix == ".svg": + with open(filename, "wt") as f: + f.write(content.as_str()) + else: + with pyvips.Image.svgload_buffer(content.as_str().encode("utf-8")) as image: + image.write_to_file(filename) if __name__ == "__main__": @@ -285,7 +290,7 @@ if __name__ == "__main__": make_wallpaper( ",".join(["#000000"] + palettes[0]["colours"]), orientation="2880x1920", - filename="testing.svg", + filename="testing.png", markers="tY.", size=3, )