python 使用gpt-image-1 创建编辑图片
python
# 创建图片
from openai import OpenAI
import base64
client = OpenAI( base_url="https://www.anyapi.vip/v1",
api_key="sk-xxx")
prompt = """
一幅儿童读物插画,画中一名兽医正用听诊器听一只水獭幼崽的心跳。
"""
result = client.images.generate(
model="gpt-image-1",
prompt=prompt
)
image_base64 = result.data[0].b64_json
image_bytes = base64.b64decode(image_base64)
# Save the image to a file
with open("otter.png", "wb") as f:
f.write(image_bytes)python
# 编辑图片
import base64
from openai import OpenAI
client = OpenAI( base_url="https://www.anyapi.vip/v1",
api_key="sk-xxx")
prompt = """
生成一张超写实图片,画面为一个放在白色背景上的礼品篮,上面标有 “放松身心” 字样,系着丝带,字体类似手写风格,礼品篮中包含参考图片里的所有物品。
"""
result = client.images.edit(
model="gpt-image-1",
image=[
open("body-lotion.png", "rb"),
open("bath-bomb.png", "rb"),
open("incense-kit.png", "rb"),
open("soap.png", "rb"),
],
prompt=prompt
)
image_base64 = result.data[0].b64_json
image_bytes = base64.b64decode(image_base64)
# Save the image to a file
with open("gift-basket.png", "wb") as f:
f.write(image_bytes)第一个效果: 第二个使用的图片:
第二个效果: