dalle-api
OpenAIのDALL-E 3 APIを活用し、テキストから画像を生成したり、既存の画像を編集・加工したりすることで、製品ビジュアルの作成やコンテンツのイラスト化など、多様な画像ニーズに応えるSkill。
📜 元の英語説明(参考)
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.
🇯🇵 日本人クリエイター向け解説
OpenAIのDALL-E 3 APIを活用し、テキストから画像を生成したり、既存の画像を編集・加工したりすることで、製品ビジュアルの作成やコンテンツのイラスト化など、多様な画像ニーズに応えるSkill。
※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。
下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o dalle-api.zip https://jpskill.com/download/14813.zip && unzip -o dalle-api.zip && rm dalle-api.zip
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/14813.zip -OutFile "$d\dalle-api.zip"; Expand-Archive "$d\dalle-api.zip" -DestinationPath $d -Force; ri "$d\dalle-api.zip"
完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。
💾 手動でダウンロードしたい(コマンドが難しい人向け)
- 1. 下の青いボタンを押して
dalle-api.zipをダウンロード - 2. ZIPファイルをダブルクリックで解凍 →
dalle-apiフォルダができる - 3. そのフォルダを
C:\Users\あなたの名前\.claude\skills\(Win)または~/.claude/skills/(Mac)へ移動 - 4. Claude Code を再起動
⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。
🎯 このSkillでできること
下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。
📦 インストール方法 (3ステップ)
- 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
- 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
- 3. 展開してできたフォルダを、ホームフォルダの
.claude/skills/に置く- · macOS / Linux:
~/.claude/skills/ - · Windows:
%USERPROFILE%\.claude\skills\
- · macOS / Linux:
Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。
詳しい使い方ガイドを見る →- 最終更新
- 2026-05-18
- 取得日時
- 2026-05-18
- 同梱ファイル
- 1
📖 Skill本文(日本語訳)
※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。
DALL-E 3 API
概要
DALL-E 3 は OpenAI の画像生成モデルであり、OpenAI Python SDK を介してアクセスできます。高いプロンプト忠実度でのテキストから画像への生成、アルファチャネルマスクを使用した画像編集をサポートし、モデルがリクエストをどのように解釈したかを示す「修正されたプロンプト(revised prompt)」を返します。
セットアップ
pip install openai python-dotenv
export OPENAI_API_KEY="your_api_key_here"
主要な概念
- Generations (
/v1/images/generations): テキストプロンプトから新しい画像を作成します。 - Edits (
/v1/images/edits): マスクされた領域を塗りつぶすことで、既存の画像を修正します。 - Variations (DALL-E 2 のみ): 既存の画像のバリエーションを生成します。
- Revised prompt: DALL-E 3 は、安全性と品質のためにプロンプトを書き換えます。実際の入力を理解するために、常に
revised_promptを記録してください。 - Response format:
url(一時的な CDN リンク、1 時間で期限切れ) またはb64_json(base64 エンコードされた PNG)。
手順
ステップ 1: クライアントの初期化
import os
import base64
import requests
from pathlib import Path
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
ステップ 2: 画像の生成 (テキストから画像へ)
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:
"""
DALL-E 3 で画像を生成します。
size options: 1024x1024 | 1792x1024 | 1024x1792
quality options: standard | hd
style options: vivid (劇的) | natural (より現実的)
保存されたパスと revised_prompt を含む dict を返します。
"""
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}")
# デコードして保存
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"
)
ステップ 3: インペインティングマスクを使用した画像編集
def edit_image(
image_path: str,
mask_path: str,
prompt: str,
size: str = "1024x1024",
output_path: str = "edited.png"
) -> str:
"""
マスクされた領域を生成されたコンテンツで置き換えることで、画像を編集します。
image_path: PNG ファイル、RGBA または RGB、正方形である必要があり、≤ 4MB
mask_path: アルファチャネルを持つ PNG ファイル。透明なピクセル = 編集する領域。
編集された画像のパスを返します。
"""
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
# 例: 製品写真の背景を置き換える
edit_image(
image_path="product.png", # 元の製品画像
mask_path="background_mask.png", # 背景領域のアルファマスク
prompt="A tropical beach at sunset as background",
size="1024x1024",
output_path="product_beach.png"
)
ステップ 4: プログラムでマスクを作成する
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:
"""
透明な円を持つインペインティングマスクを作成します。
center_x/y: 0.0–1.0 相対位置
radius: 0.0–0.5 相対半径
"""
img = Image.open(image_path).convert("RGBA")
w, h = img.size
mask = Image.new("RGBA", (w, h), (255, 255, 255, 255)) # 完全に不透明
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 # 透明 = 編集する領域
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")
ステップ 5: バッチ生成
import time
def batch_generate(prompts: list[str], size: str = "1024x1024",
quality: str = "standard", output_dir: str = "output/") -> list[str]:
"""レート制限処理で複数の画像を生成します。"""
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) # レート制限を尊重します (標準ティアでは 5 画像/分)
except Exception as e:
print(f"Error on prompt {i}: {e}")
time.sleep(5)
return paths
products = [
"A wooden cutting b 📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開
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_promptto understand the actual input. - Response format:
url(temporary CDN link, expires in 1 hour) orb64_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_promptto 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/editsendpoint only supports DALL-E 2. - URL expiry: Response URLs expire after 1 hour. Always download and store images immediately.
Guidelines
- Use
quality="hd"andstyle="natural"for photorealistic product images. - Use
quality="standard"andstyle="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_jsoninstead ofurlformat 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.