41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
import urllib2
|
|
import urllib
|
|
import os
|
|
|
|
# create save directory
|
|
save_dir = r"e:\Temp\desktop-pets\images"
|
|
if not os.path.exists(save_dir):
|
|
os.makedirs(save_dir)
|
|
|
|
# image API base URL
|
|
base_url = "https://trae-api-cn.mchost.guru/api/ide/v1/text_to_image"
|
|
|
|
# cockroach action list
|
|
cockroach_actions = [
|
|
("cockroach_idle.png", "pixel art cockroach standing still, cute pixel style, transparent background, 64x64 pixels, dark brown color, detailed antennae, cartoon style"),
|
|
("cockroach_walk1.png", "pixel art cockroach walking pose 1, cute pixel style, transparent background, 64x64 pixels, dark brown color, legs in motion, cartoon style"),
|
|
("cockroach_walk2.png", "pixel art cockroach walking pose 2, cute pixel style, transparent background, 64x64 pixels, dark brown color, legs in different position, cartoon style"),
|
|
("cockroach_crawl.png", "pixel art cockroach crawling low, cute pixel style, transparent background, 64x64 pixels, dark brown color, cartoon style"),
|
|
("cockroach_scared.png", "pixel art cockroach scared pose, antennae raised, cute pixel style, transparent background, 64x64 pixels, dark brown color, cartoon style")
|
|
]
|
|
|
|
# download each image
|
|
for filename, prompt in cockroach_actions:
|
|
print("Generating: " + filename)
|
|
url = base_url + "?prompt=" + urllib.quote(prompt) + "&image_size=square_hd"
|
|
|
|
try:
|
|
response = urllib2.urlopen(url, timeout=60)
|
|
image_data = response.read()
|
|
|
|
# save image
|
|
save_path = os.path.join(save_dir, filename)
|
|
with open(save_path, 'wb') as f:
|
|
f.write(image_data)
|
|
print("Saved: " + save_path)
|
|
except Exception as e:
|
|
print("Failed to generate " + filename + ": " + str(e))
|
|
|
|
print("All images generated!")
|