# 네이버 블로그 이미지 생성 — 유형별 라우팅 (Satori + Gemini)

## 배경
- Gemini 이미지 생성이 인포그래픽/비교표에 부적합 — 프롬프트 텍스트를 이미지 안에 렌더링
- 해결: 유형별 라우팅
  - photo → Gemini (포토리얼리스틱)
  - infographic/comparison_table/checklist/process_flow → Satori (HTML→이미지)

## 수정 대상
- `/home/jay/workspace/dashboard/server.py` — `/api/naver-blog/generate-images` 핸들러
- `/home/jay/workspace/tools/ai-image-gen/image_router.py` — 라우팅 로직

## 수정 내용

### 1. 이미지 프롬프트 유형 파싱
프론트엔드에서 전달되는 프롬프트에 유형 태그 포함:
```
[이미지프롬프트: infographic|상세설명...]
[이미지프롬프트: photo|상세설명...]
```
`type|description` 파싱하여 라우팅

### 2. 유형별 라우팅

#### photo → Gemini
- 기존 `_generate_gemini()` 사용
- 프롬프트를 간결하게 정리 (100단어 이내)
- 영어로 번역하여 전달 (Gemini 영어 프롬프트가 품질 높음)

#### infographic / comparison_table / checklist / process_flow → Satori
- 프롬프트를 기반으로 HTML 템플릿 생성
- Claude CLI로 "이 설명에 맞는 Satori용 HTML 코드를 작성해줘" 프롬프트
- 생성된 HTML을 Satori로 렌더링 → PNG
- Satori 렌더링: `satori-cardnews` 스킬 참조 또는 직접 satori 호출
  - satori 사용법: `/home/jay/workspace/memory/projects/threadauto/cardnews-cli-guide.md` 참조

### 3. Satori HTML→PNG 변환
```python
import subprocess

def _generate_satori_image(html_content: str, output_path: Path, width: int = 740) -> bool:
    """Satori로 HTML을 PNG로 렌더링"""
    html_path = output_path.with_suffix('.html')
    html_path.write_text(html_content, encoding='utf-8')
    
    result = subprocess.run(
        ["node", "/home/jay/projects/ThreadAuto/renderer/satori_render.js", 
         str(html_path), str(output_path), str(width)],
        capture_output=True, text=True, timeout=30
    )
    return output_path.exists()
```
- Satori 렌더러 경로 확인 필요
- 없으면 `npx @vercel/og` 또는 직접 구현

### 4. HTML 템플릿 생성
Claude CLI로 프롬프트 → HTML 변환:
```python
def _prompt_to_html(description: str, img_type: str) -> str:
    prompt = f"""아래 설명을 기반으로 {img_type} 스타일의 HTML 코드를 작성해주세요.
- 크기: 740px x 500px
- 배경: 흰색
- 폰트: Pretendard (font-family: 'Pretendard', sans-serif)
- 스타일: 깔끔한 인포그래픽, 파란-회색 색상 팔레트
- 한국어 텍스트
- inline CSS만 사용
- 외부 리소스 없이 자체 완결

설명: {description}

HTML 코드만 출력하세요 (```html 태그 없이):"""
    
    result = subprocess.run(
        ["/home/jay/.local/bin/claude", "-p", prompt, "--model", "haiku"],
        capture_output=True, text=True, timeout=60, cwd="/tmp"
    )
    return result.stdout.strip()
```

### 5. 프론트엔드 변경 없음
- 기존 이미지 프롬프트 UI 그대로 유지
- 유형 태그는 글 생성 시 LLM이 자동 부여

## 테스트
1. infographic 유형 → Satori HTML→PNG 생성 확인 (한글 정확)
2. photo 유형 → Gemini 포토리얼리스틱 생성 확인
3. comparison_table → Satori 비교표 이미지 확인
4. 전체 7개 이미지 생성 흐름 테스트

## 보고서
`/home/jay/workspace/memory/reports/task-1610.md`에 작성