gpt-image-1楽しいですね。
ChatGPTの4oで画像をジブリ風にして!などが流行ってましたがその機能が使えるAPIって感じです。
画像をインプットして画像を出力するのでImage to Imageです。
準備
APIキーは認証が必要なのでやっておきましょう。
ちなみにNode.jsはv24にしてます。
プロンプト
プロンプトはこちらです。「この画像をジブリ風にしてください」をプロンプトにすると?をo4-miniに考えてもらいまいました。
“ → Transform the input image into a hand-painted Studio Ghibli-style illustration.
• Use a soft pastel color palette and watercolor-like textures
• Warm, natural lighting with gentle atmospheric haze
• Painterly brush strokes, delicate gradients, and subtle film grain
• Whimsical details: floating petals, glowing fireflies, drifting dust motes
• Lush, detailed backgrounds (rolling hills, ancient trees, quaint villages, or misty forests)
• Characters (if present): large expressive eyes, gentle facial expressions, flowing hair/clothes
• Preserve original composition and silhouette
• Render at high resolution (e.g. 4K), no text or logos
”
コードなど
本当にサンプルを触ったくらいですが
import fs from "fs";
import OpenAI, { toFile } from "openai";
const client = new OpenAI({apiKey: `APIキー`});
const imageFiles = [
"kanda-matsuri.png"
];
const images = await Promise.all(
imageFiles.map(async (file) =>
await toFile(fs.createReadStream(file), null, {
type: "image/png",
})
),
);
const rsp = await client.images.edit({
model: "gpt-image-1",
image: images,
prompt: `
→ Transform the input image into a hand-painted Studio Ghibli-style illustration.
• Use a soft pastel color palette and watercolor-like textures
• Warm, natural lighting with gentle atmospheric haze
• Painterly brush strokes, delicate gradients, and subtle film grain
• Whimsical details: floating petals, glowing fireflies, drifting dust motes
• Lush, detailed backgrounds (rolling hills, ancient trees, quaint villages, or misty forests)
• Characters (if present): large expressive eyes, gentle facial expressions, flowing hair/clothes
• Preserve original composition and silhouette
• Render at high resolution (e.g. 4K), no text or logos
`,
});
// Save the image to a file
const image_base64 = rsp.data[0].b64_json;
const image_bytes = Buffer.from(image_base64, "base64");
fs.writeFileSync("kanda-matsuri-new-1.png", image_bytes);
出力
画像が生成されました。
元画像
!function(f,b,e,v,n,t,s)
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version=’2.0′;
n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];
s.parentNode.insertBefore(t,s)}(window, document,’script’,
‘https://connect.facebook.net/en_US/fbevents.js’);
fbq(‘init’, ‘305156090176370’);
fbq(‘trackSingle’, ‘305156090176370’, ‘PageView’);
続きを読む
Views: 0