Add new game assets and update asset paths in code
This commit is contained in:
1 parent
53e98cf3fe
commit
69484866db
20 files changed
+228
-36
No files matched your search
@@ -373,23 +373,32 @@ def _api_key() -> str:
|
||||
|
||||
|
||||
def generate_image(prompt: str, model: str, size: int,
|
||||
transparent: bool = False) -> Image.Image:
|
||||
transparent: bool = False,
|
||||
aspect_ratio: str = "1:1") -> Image.Image:
|
||||
"""Call the OpenRouter image API and return the decoded PIL image.
|
||||
|
||||
Requests a square image at `size` px and decodes the base64 PNG/JPEG/WebP
|
||||
bytes returned in `data[].b64_json`. The requested size is clamped to at
|
||||
least GEN_SIZE because some models (e.g. seedream) reject small outputs;
|
||||
callers downscale the result to MAX_DIM afterwards. When `transparent` is
|
||||
true, the API is asked for a transparent background (PNG alpha).
|
||||
Requests a square image at `size` px or a role-shaped image at the matching
|
||||
resolution tier and decodes `data[].b64_json`. Seedream's square requests
|
||||
retain the existing GEN_SIZE floor. When `transparent` is true, the API is
|
||||
asked for a transparent PNG background.
|
||||
"""
|
||||
size = max(GEN_SIZE, int(size))
|
||||
size = max(1, int(size))
|
||||
if model == DEFAULT_IMAGE_MODEL:
|
||||
size = max(GEN_SIZE, size)
|
||||
body = {
|
||||
"model": model,
|
||||
"prompt": prompt,
|
||||
"size": f"{size}x{size}",
|
||||
"output_format": "png",
|
||||
"n": 1,
|
||||
}
|
||||
if aspect_ratio == "1:1":
|
||||
body["size"] = f"{size}x{size}"
|
||||
else:
|
||||
body["aspect_ratio"] = aspect_ratio
|
||||
body["resolution"] = next(
|
||||
(tier for limit, tier in ((512, "512"), (768, "768"), (1024, "1K"),
|
||||
(1536, "1.5K"), (2048, "2K"), (4096, "4K"))
|
||||
if size <= limit), "4K")
|
||||
if transparent:
|
||||
body["background"] = "transparent"
|
||||
req = urllib.request.Request(
|
||||
|
||||
Reference in new issue
Block a user