STAGE 16 · Lv.80
이미지 자동 생성과 특성 이미지
DALL-E/Midjourney API를 연동하여 자동으로 특성 이미지를 생성하고, 이미지 리사이징, alt 텍스트 자동 생성, 미디어 라이브러리 관리를 구현합니다.
AI 이미지 생성의 전략적 활용
블로그 이미지가 트래픽에 미치는 영향
블로그 포스트에서 특성 이미지(Featured Image)는 클릭률에 결정적인 영향을 미칩니다. BuzzSumo의 분석에 따르면, 이미지가 포함된 기사는 Facebook에서 2.3배, Twitter에서 1.5배 더 많은 참여를 얻습니다. SNS에서 글이 공유될 때 이미지가 없으면 텍스트만 표시되어 눈에 띄지 않습니다.
하지만 매번 적절한 이미지를 찾거나 디자인하는 것은 시간과 비용이 많이 소요됩니다. 스톡 이미지는 다른 사이트와 중복되어 브랜드 차별화가 어렵고, 디자이너에게 매번 의뢰하면 글 한 편당 수만 원의 비용이 발생합니다.
DALL-E 3, Stable Diffusion 등의 AI 이미지 생성 API를 WordPress에 통합하면, 글의 주제에 맞는 고유한 이미지를 자동으로 생성하여 특성 이미지로 설정할 수 있습니다. 글 작성과 동시에 이미지가 자동 생성되므로 워크플로우가 획기적으로 단순해집니다.
DALL-E 3
OpenAI 고품질 이미지 생성
$0.04~0.12
이미지 1장당 비용
AI Alt 텍스트
접근성 + SEO 자동 설정
자동 WebP
이미지 최적화 자동 변환
| 이미지 생성 API | 비용 | 품질 | 최대 해상도 | 특징 |
|---|---|---|---|---|
| DALL-E 3 | $0.04~0.12/장 | 매우 우수 | 1792x1024 | 텍스트 렌더링 우수, 프롬프트 정확도 높음 |
| DALL-E 2 | $0.016~0.02/장 | 우수 | 1024x1024 | 저렴, 대량 생산에 적합 |
| Stable Diffusion API | $0.002~0.02/장 | 우수 | 2048x2048 | 최저 비용, 다양한 모델, 커스텀 가능 |
| Midjourney API | 구독 기반 | 최상 | 2048x2048 | 예술적 품질 최고, 비공식 API |
DALL-E 3 API 연동 전체 코드
// AI 이미지 생성 핵심 클래스
class MAP_AI_Image_Generator {
private $api_key;
private $default_style;
private $default_quality;
public function __construct() {
$this->api_key = get_option('map_openai_api_key');
$this->default_style = get_option('map_image_style', 'modern');
$this->default_quality = get_option('map_image_quality', 'standard');
}
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// DALL-E 3로 이미지 생성
// ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
public function generate_dalle($prompt, $options = []) {
$defaults = [
'size' => '1792x1024', // 블로그 와이드 비율
'quality' => $this->default_quality, // standard 또는 hd
'style' => 'natural', // natural 또는 vivid
'model' => 'dall-e-3',
];
$opts = wp_parse_args($options, $defaults);
$response = wp_remote_post('https://api.openai.com/v1/images/generations', [
'headers' => [
'Authorization' => 'Bearer ' . $this->api_key,
'Content-Type' => 'application/json',
],
'body' => wp_json_encode([
'model' => $opts['model'],
'prompt' => $prompt,
'n' => 1,
'size' => $opts['size'],
'quality' => $opts['quality'],
'style' => $opts['style'],
'response_format' => 'url',
]),
'timeout' => 90,
]);
if (is_wp_error($response)) {
error_log('[AI Image] DALL-E 오류: ' . $response->get_error_message());
return false;
}
$code = wp_remote_retrieve_response_code($response);
$body = json_decode(wp_remote_retrieve_body($response), true);
if ($code !== 200) {
$error = $body['error']['message'] ?? '알 수 없는 오류';
error_log("[AI Image] DALL-E HTTP {$code}: {$error}");
return false;
}
return [
'url' => $body['data'][0]['url'] ?? false,
'revised_prompt' => $body['data'][0]['revised_prompt'] ?? '',
];
}
// Stable Diffusion API로 이미지 생성 (Stability AI)
public function generate_stable_diffusion($prompt, $options = []) {
$sd_key = get_option('map_stability_api_key');
if (!$sd_key) return false;
$defaults = [
'width' => 1344,
'height' => 768,
'steps' => 30,
'cfg_scale' => 7,
'engine' => 'stable-diffusion-xl-1024-v1-0',
];
$opts = wp_parse_args($options, $defaults);
$response = wp_remote_post(
"https://api.stability.ai/v1/generation/{$opts['engine']}/text-to-image",
[
'headers' => [
'Authorization' => 'Bearer ' . $sd_key,
'Content-Type' => 'application/json',
'Accept' => 'application/json',
],
'body' => wp_json_encode([
'text_prompts' => [
['text' => $prompt, 'weight' => 1],
['text' => 'blurry, text, watermark, low quality, deformed', 'weight' => -1],
],
'width' => $opts['width'],
'height' => $opts['height'],
'steps' => $opts['steps'],
'cfg_scale' => $opts['cfg_scale'],
'samples' => 1,
]),
'timeout' => 90,
]
);
if (is_wp_error($response)) return false;
$body = json_decode(wp_remote_retrieve_body($response), true);
$base64 = $body['artifacts'][0]['base64'] ?? null;
if (!$base64) return false;
// base64를 임시 파일로 저장
$tmp_file = wp_tempnam('sd_image_') . '.png';
file_put_contents($tmp_file, base64_decode($base64));
return ['file' => $tmp_file, 'type' => 'file'];
}
// 블로그 주제에 맞는 이미지 프롬프트 자동 생성
public function create_blog_image_prompt($title, $style = null) {
$style = $style ?: $this->default_style;
$styles = [
'modern' => 'clean modern flat illustration, minimalist design, soft gradient colors, geometric shapes',
'photo' => 'professional stock photo style, high quality, well lit, shallow depth of field',
'abstract' => 'abstract geometric art, vibrant colors, contemporary design, flowing shapes',
'isometric' => 'isometric 3D illustration, pastel colors, tech themed, clean background',
'watercolor' => 'watercolor painting style, soft edges, artistic, delicate colors',
'gradient' => 'beautiful gradient background, abstract, minimal with subtle tech elements',
'line_art' => 'clean line art illustration, single color, white background, professional',
];
$style_desc = $styles[$style] ?? $styles['modern'];
return sprintf(
"Blog featured image for article titled '%s'. Style: %s. IMPORTANT: No text, no letters, no words, no watermarks in the image. Wide landscape aspect ratio suitable for blog header. Professional and visually appealing.",
sanitize_text_field($title),
$style_desc
);
}
// AI로 스마트 프롬프트 생성 (글 내용 분석 기반)
public function create_smart_prompt($post_id, $style = null) {
$post = get_post($post_id);
if (!$post) return false;
$connector = new MAP_AI_Connector();
$excerpt = mb_substr(strip_tags($post->post_content), 0, 500);
$result = $connector->call(
'You are an expert at creating DALL-E image prompts for blog featured images.',
sprintf(
"Create a DALL-E 3 prompt for a blog featured image.
Blog title: %s
Content excerpt: %s
Style preference: %s
Requirements:
- No text or letters in the image
- Wide landscape format (16:9)
- Professional and clean
- Visually represents the topic
Respond with ONLY the prompt text, nothing else.",
$post->post_title,
$excerpt,
$style ?: $this->default_style
),
0.8, 300
);
return $result['content'] ?? $this->create_blog_image_prompt($post->post_title, $style);
}
}
🔒
여기까지는 미리보기입니다
이미지 자동 생성과 특성 이미지
무료 가입하면 이어서 볼 수 있고, 강의를 완료할 때마다 XP와 레벨이 쌓입니다.
Google로 3초 만에 시작 →🧵 Threads로 시작무료 공개 강의 둘러보기 (Lv.1~3)무료 가입하면 이어서 볼 수 있고, 강의를 완료할 때마다 XP와 레벨이 쌓입니다.