dalle-api

DALL·E 3 API,用于文本生成图像、图像编辑及生成图像变体。适用于根据文本提示生成图像、创建产品视觉图与内容插图,或使用修复蒙版进行图像编辑的场景。

仓库最近推送
GitHub Stars
219
Forks
38
Issues / PRs
1

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "dalle-api":https://skillpi.com/zh/skills/deepskill-5c1d09eb4b9d05986300a1518f7784059afb97368931aa3aa4c6cc7c760e4eed。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

DALL·E 3 API,用于文本生成图像、图像编辑及生成图像变体。适用于根据文本提示生成图像、创建产品视觉图与内容插图,或使用修复蒙版进行图像编辑的场景。

0 下载

介绍来源: third_party · TerminalSkills · 1.0.0 参考来源

SkillPi 解读

实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: dalle-api
description: >-
  DALL-E 3 API for AI image generation — text-to-image, image editing, and
  variations via OpenAI. Use when generating images from text prompts, creating
  product visuals, illustrating content, or editing images with an inpainting
  mask.
license: Apache-2.0
compatibility: "Requires Python 3.9+ or Node.js 18+. Install: pip install openai. OpenAI API key required."
metadata:
  author: terminal-skills
  version: "1.0.0"
  category: data-ai
  tags: ["dalle", "openai", "image-generation", "text-to-image", "ai-art"]
  use-cases:
    - "Generate product visuals from text descriptions for e-commerce listings"
    - "Create custom illustrations for blog articles or social media"
    - "Edit an existing image by replacing a region using an inpainting mask"
  agents: [claude-code, openai-codex, gemini-cli, cursor]

DALL-E 3 API

Overview

DALL-E 3 is OpenAI's image generation model, accessible via the OpenAI Python SDK. It supports text-to-image generation with high prompt fidelity, image editing with alpha-channel masks, and returns a "revised prompt" showing how the model interpreted your request.

Setup

pip install openai python-dotenv
export OPENAI_API_KEY="your_api_key_here"

Core Concepts

  • Generations (/v1/images/generations): Create a new image from a text prompt.
  • Edits (/v1/images/edits): Modify an existing image by painting over a masked region.
  • Variations (DALL-E 2 only): Generate variations of an existing image.
  • Revised prompt: DALL-E 3 rewrites your prompt for safety and quality — always log revised_prompt to understand the actual input.
  • Response format: url (temporary CDN link, expires in 1 hour) or b64_json (base64-encoded PNG).

Instructions

Step 1: Initialize the client

import os
import base64
import requests
from pathlib import Path
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

Step 2: Generate an image (text-to-image)

def generate_image(
    prompt: str,
    model: str = "dall-e-3",
    size: str = "1024x1024",
    quality: str = "standard",
    style: str = "vivid",
    output_path: str = "output.png"
) -> dict:
    """
    Generate an image with DALL-E 3.

    size options:       1024x1024 | 1792x1024 | 1024x1792
    quality options:    standard | hd
    style options:      vivid (dramatic) | natural (more realistic)
    Returns dict with saved path and revised_prompt.
    """
    response = client.images.generate(
        model=model,
        prompt=prompt,
        size=size,
        quality=quality,
        style=style,
        n=1,
        response_format="b64_json"
    )

    image_data = response.data[0]
    revised_prompt = image_data.revised_prompt
    print(f"Revised prompt: {revised_prompt}")

    # Decode and save
    img_bytes = base64.b64decode(image_data.b64_json)
    Path(output_path).write_bytes(img_bytes)
    size_kb = len(img_bytes) // 1024
    print(f"Saved: {output_path} ({size_kb} KB)")

    return {"path": output_path, "revised_prompt": revised_prompt}

# Standard quality, vivid style
result = generate_image(
    prompt="A sleek electric car driving through a futuristic city at night, neon reflections on wet streets, cinematic",
    size="1792x1024",
    quality="standard",
    style="vivid",
    output_path="electric_car.png"
)

# HD quality, natural style for photorealism
result = generate_image(
    prompt="A professional headshot of a confident businesswoman in a modern office, natural lighting, 50mm lens",
    size="1024x1024",
    quality="hd",
    style="natural",
    output_path="headshot.png"
)

Step 3: Image editing with inpainting mask

def edit_image(
    image_path: str,
    mask_path: str,
    prompt: str,
    size: str = "1024x1024",
    output_path: str = "edited.png"
) -> str:
    """
    Edit an image by replacing the masked region with generated content.

    image_path: PNG file, RGBA or RGB, must be square, ≤ 4MB
    mask_path:  PNG file with alpha channel. Transparent pixels = area to edit.
    Returns path to the edited image.
    """
    with open(image_path, "rb") as img_f, open(mask_path, "rb") as mask_f:
        response = client.images.edit(
            model="dall-e-2",  # edits require dall-e-2
            image=img_f,
            mask=mask_f,
            prompt=prompt,
            size=size,
            n=1,
            response_format="b64_json"
        )

    img_bytes = base64.b64decode(response.data[0].b64_json)
    Path(output_path).write_bytes(img_bytes)
    print(f"Edited image saved: {output_path}")
    return output_path

# Example: replace the background of a product photo
edit_image(
    image_path="product.png",          # Original product image
    mask_path="background_mask.png",   # Alpha mask over background area
    prompt="A tropical beach at sunset as background",
    size="1024x1024",
    output_path="product_beach.png"
)

Step 4: Create a mask programmatically

from PIL import Image  # pip install Pillow
import numpy as np

def create_circular_mask(image_path: str, center_x: float = 0.5, center_y: float = 0.5,
                          radius: float = 0.3, output_path: str = "mask.png") -> str:
    """
    Create an inpainting mask with a transparent circle.
    center_x/y: 0.0–1.0 relative position
    radius: 0.0–0.5 relative radius
    """
    img = Image.open(image_path).convert("RGBA")
    w, h = img.size
    mask = Image.new("RGBA", (w, h), (255, 255, 255, 255))  # fully opaque

    cx, cy, r = int(w * center_x), int(h * center_y), int(min(w, h) * radius)
    mask_arr = np.array(mask)
    Y, X = np.ogrid[:h, :w]
    dist = np.sqrt((X - cx)**2 + (Y - cy)**2)
    mask_arr[dist <= r, 3] = 0  # transparent = area to edit
    Image.fromarray(mask_arr).save(output_path)
    print(f"Mask saved: {output_path}")
    return output_path

create_circular_mask("product.png", center_x=0.5, center_y=0.5, radius=0.4, output_path="circle_mask.png")

Step 5: Batch generation

import time

def batch_generate(prompts: list[str], size: str = "1024x1024",
                   quality: str = "standard", output_dir: str = "output/") -> list[str]:
    """Generate multiple images with rate-limit handling."""
    Path(output_dir).mkdir(exist_ok=True)
    paths = []
    for i, prompt in enumerate(prompts):
        try:
            out_path = f"{output_dir}/image_{i:03d}.png"
            result = generate_image(prompt, size=size, quality=quality, output_path=out_path)
            paths.append(result["path"])
            time.sleep(1)  # respect rate limits (5 images/min on standard tier)
        except Exception as e:
            print(f"Error on prompt {i}: {e}")
            time.sleep(5)
    return paths

products = [
    "A wooden cutting board with fresh vegetables, overhead shot, natural light",
    "A ceramic mug with steam rising, cozy kitchen background, warm tones",
    "A leather wallet on a marble surface, minimal style, luxury feel"
]
batch_generate(products, quality="hd", output_dir="product_shots")

Parameters reference

Parameter Values Description
model dall-e-3, dall-e-2 DALL-E 3 = generations only; DALL-E 2 = edits + variations
size 1024x1024, 1792x1024, 1024x1792 Output dimensions (DALL-E 3)
quality standard, hd hd has finer details, costs 2x credits
style vivid, natural vivid = dramatic; natural = more realistic
response_format url, b64_json URL expires in 1 hour; b64_json is permanent
n 1 (DALL-E 3) DALL-E 3 supports n=1 only

DALL-E 3 behaviors to know

  • Prompt rewriting: DALL-E 3 automatically rewrites prompts. Log revised_prompt to understand what was actually generated.
  • Safety filters: Some content is refused and returns an error. The revised prompt handles most edge cases automatically.
  • No n>1: DALL-E 3 only generates 1 image per API call. Use a loop for batches.
  • Edits use DALL-E 2: The /v1/images/edits endpoint only supports DALL-E 2.
  • URL expiry: Response URLs expire after 1 hour. Always download and store images immediately.

Guidelines

  • Use quality="hd" and style="natural" for photorealistic product images.
  • Use quality="standard" and style="vivid" for illustrations, concept art, and marketing visuals.
  • For best results, be specific: include subject, style, lighting, camera angle, and mood in the prompt.
  • Use b64_json instead of url format to avoid download failures on slow networks.
  • Rate limits: ~5 images/minute on standard tier. Add time.sleep(1) between batch requests.
  • Store API keys in environment variables — never hardcode them.

当前收录版本

1.0.0

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值92/100

亮点

  • 提供完整的 DALL-E 3 图像生成、编辑与批处理功能,满足电商、内容创作等高频刚需场景
  • 详细说明 revised_prompt 机制与参数选择策略,显著提升用户生成质量
触发精准90/100

亮点

  • 触发描述完整覆盖 text-to-image、image editing、variations 三大核心能力
  • 使用场景明确(产品视觉、插图、图像修复),边界清晰无歧义
结构规范95/100

待提升项

  • 缺少独立 'When to Use' 章节 原报告严重程度:轻微

    文档未设置显式的 'When to Use' 章节,尽管 frontmatter 中有 use-cases 和 description 说明

    改进建议:建议在 Overview 后增加独立 'When to Use' 章节,提升可读性

亮点

  • 结构清晰:Setup → Core Concepts → 分步 Instructions → Parameters → Guidelines
  • 提供完整端到端代码示例(单图生成、图像编辑、批处理),含参数说明与错误处理
执行可靠88/100

亮点

  • 工具来源明确(OpenAI SDK),参数说明完整(size/quality/style/response_format)
  • 覆盖主要异常场景:批处理中实现 rate limit 处理(time.sleep)与异常捕获
  • 明确说明 DALL-E 3 仅支持 n=1、edits 需用 DALL-E 2 等关键限制
证据可验 (前四项均值)91/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。