save as different image formats (pyvips)

This commit is contained in:
julius 2024-10-27 19:28:02 +01:00
parent 9f5bb724cb
commit 0ee3e39c3c
Signed by: julius
GPG Key ID: C80A63E6A5FD7092

View File

@ -1,5 +1,6 @@
import itertools import itertools
from pathlib import Path from pathlib import Path
import pyvips
import logging import logging
from perlin import CoordsGenerator from perlin import CoordsGenerator
import svg import svg
@ -253,8 +254,12 @@ def make_wallpaper(
) )
content = svg.SVG(width=x, height=y, elements=elements) content = svg.SVG(width=x, height=y, elements=elements)
if Path(filename).suffix == ".svg":
with open(filename, "wt") as f: with open(filename, "wt") as f:
f.write(content.as_str()) 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__": if __name__ == "__main__":
@ -285,7 +290,7 @@ if __name__ == "__main__":
make_wallpaper( make_wallpaper(
",".join(["#000000"] + palettes[0]["colours"]), ",".join(["#000000"] + palettes[0]["colours"]),
orientation="2880x1920", orientation="2880x1920",
filename="testing.svg", filename="testing.png",
markers="tY.", markers="tY.",
size=3, size=3,
) )