jpg and png works
This commit is contained in:
parent
b4e70c2245
commit
3220b6aa64
@ -1,9 +1,10 @@
|
|||||||
import random
|
|
||||||
import json
|
import json
|
||||||
|
import random
|
||||||
|
|
||||||
from main import make_wallpaper
|
from speckles import make_wallpaper
|
||||||
|
|
||||||
palettes = [
|
palettes = [
|
||||||
|
{"colours": ["#DE4A21", "#6F04F2", "#490B1C", "#4a9c9e"], "votes": 1000000},
|
||||||
{"colours": ["#eee4ab", "#e5cb9f", "#99c4c8", "#68a7ad"], "votes": 100000},
|
{"colours": ["#eee4ab", "#e5cb9f", "#99c4c8", "#68a7ad"], "votes": 100000},
|
||||||
{"colours": ["#e4d192", "#cba0ae", "#af7ab3", "#80558c"], "votes": 100000},
|
{"colours": ["#e4d192", "#cba0ae", "#af7ab3", "#80558c"], "votes": 100000},
|
||||||
{"colours": ["#eeeeee", "#e1d4bb", "#cbb279", "#537188"], "votes": 100000},
|
{"colours": ["#eeeeee", "#e1d4bb", "#cbb279", "#537188"], "votes": 100000},
|
||||||
@ -30,10 +31,17 @@ with open("popular.json", "r") as f:
|
|||||||
palettes += json.load(f)
|
palettes += json.load(f)
|
||||||
|
|
||||||
palette = random.choice(palettes)
|
palette = random.choice(palettes)
|
||||||
colours = ["black"] + palette["colours"]
|
enabled_markers = "otY+xP*"
|
||||||
with open("current_speckles.png", "wb") as f:
|
markers = random.choices(enabled_markers, k=random.randint(1, len(enabled_markers)))
|
||||||
|
for i, palette in enumerate(palettes):
|
||||||
|
colours = ["black"] + palette["colours"]
|
||||||
b = make_wallpaper(
|
b = make_wallpaper(
|
||||||
",".join(colours), fileformat="png", size=2.1, density=0.3, local=True
|
",".join(colours),
|
||||||
|
fileformat="png",
|
||||||
|
size=2.1,
|
||||||
|
density=0.2,
|
||||||
|
filename=f"wallpapers/speckles{i}_2880x1800.png",
|
||||||
|
perlin=True,
|
||||||
|
markers=enabled_markers,
|
||||||
|
orientation="2880x1800",
|
||||||
)
|
)
|
||||||
# for body in b.body_iterator:
|
|
||||||
# print(body)
|
|
||||||
|
@ -296,9 +296,11 @@ def make_wallpaper(
|
|||||||
if fileformat == "svg":
|
if fileformat == "svg":
|
||||||
buf = io.BytesIO(content.as_str().encode("utf-8"))
|
buf = io.BytesIO(content.as_str().encode("utf-8"))
|
||||||
buf.seek(0)
|
buf.seek(0)
|
||||||
else:
|
elif fileformat in ["jpg", "png"]:
|
||||||
with pyvips.Image.svgload_buffer(content.as_str().encode("utf-8")) as image:
|
with pyvips.Image.svgload_buffer(content.as_str().encode("utf-8")) as image:
|
||||||
buf = image.write_to_buffer("." + fileformat)
|
data = image.write_to_buffer("." + fileformat)
|
||||||
|
buf = io.BytesIO(data)
|
||||||
|
buf.seek(0)
|
||||||
return StreamingResponse(content=buf, media_type=MEDIA_TYPES[fileformat])
|
return StreamingResponse(content=buf, media_type=MEDIA_TYPES[fileformat])
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user