
    i=)                    ^   d Z ddlmZ ddlZddlZddlZddlZddlZddlm	Z	 ddl
mZ ddlZ e	e      j                  Zej                   j#                  d ee              e	d      Zedz  Zedz  Zed	z  Zed
z  Z e	j0                         dz  ZdZdZddZddZddZedk(  r e        yy)uv   컨셉 #07 Impact Number v2 - hybrid-image 파이프라인
Gemini 배경 생성 + Playwright HTML 오버레이 합성
    )annotationsN)Path)AnyzD/home/jay/workspace/output/meta-ads/concept-catalog/07-impact-numberzbg_v2_impact.jpgzsample-v2.pngz07-impact-number-v2.pngzoverlay_impact_v2.htmlz.local/share/fonts/PretendardaQ  Very dark navy blue background (#121928), minimal abstract composition. Subtle golden radial glow emanating from center, soft warm amber-gold light diffusion. Pure dark gradient background, no patterns, no text, no objects, no people. Just deep dark navy with a gentle golden center glow. Clean, simple, elegant. 1080x1080 square format.u  <!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<style>
  @font-face {{
    font-family: 'Pretendard';
    src: url('file://{font_dir}/Pretendard-Regular.otf') format('opentype');
    font-weight: 400;
    font-style: normal;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('file://{font_dir}/Pretendard-Medium.otf') format('opentype');
    font-weight: 500;
    font-style: normal;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('file://{font_dir}/Pretendard-SemiBold.otf') format('opentype');
    font-weight: 600;
    font-style: normal;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('file://{font_dir}/Pretendard-Bold.otf') format('opentype');
    font-weight: 700;
    font-style: normal;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('file://{font_dir}/Pretendard-Black.otf') format('opentype');
    font-weight: 900;
    font-style: normal;
  }}

  * {{
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }}

  html, body {{
    width: 1080px;
    height: 1080px;
    overflow: hidden;
    background: #121928;
  }}

  .canvas {{
    width: 1080px;
    height: 1080px;
    position: relative;
    background-image: url('file://{bg_path}');
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }}

  /* 배경 다크 오버레이 (배경 이미지 너무 밝을 경우 보정) */
  .canvas::before {{
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(
      ellipse 60% 55% at 50% 50%,
      rgba(240, 200, 74, 0.08) 0%,
      rgba(18, 25, 40, 0.0) 60%,
      rgba(18, 25, 40, 0.3) 100%
    );
    pointer-events: none;
  }}

  .content-stack {{
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    /* 수직 중앙 정렬은 부모 flex center로 처리 */
  }}

  /* 1. 서브 라벨 */
  .sub-label {{
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-weight: 400;
    font-size: 48px;
    color: #E0E8F0;
    text-align: center;
    letter-spacing: -0.5px;
    margin-bottom: 16px;
  }}

  /* 2. 임팩트 숫자 */
  .impact-number {{
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-weight: 900;
    font-size: 200px;
    color: #F0C84A;
    text-align: center;
    letter-spacing: -6px;
    line-height: 1;
    white-space: nowrap;
    /* 골드 글로우 효과 */
    text-shadow:
      0 0 40px rgba(240, 200, 74, 0.9),
      0 0 80px rgba(240, 200, 74, 0.5),
      0 0 120px rgba(240, 200, 74, 0.3),
      0 0 200px rgba(240, 200, 74, 0.15);
    margin-bottom: 32px;
  }}

  /* 3. 구분선 */
  .divider {{
    width: 120px;
    height: 1px;
    background: #F0C84A;
    margin-bottom: 28px;
    opacity: 0.85;
  }}

  /* 4. 긴급성 */
  .urgency {{
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-weight: 700;
    font-size: 52px;
    color: #E06060;
    text-align: center;
    letter-spacing: -0.5px;
    line-height: 1.2;
    margin-bottom: 20px;
  }}

  /* 5. CTA */
  .cta {{
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-weight: 600;
    font-size: 44px;
    color: #FFFFFF;
    text-align: center;
    letter-spacing: -0.3px;
    opacity: 0.95;
  }}
</style>
</head>
<body>
  <div class="canvas">
    <div class="content-stack">
      <div class="sub-label">신입 정착지원금 최대</div>
      <div class="impact-number">1,000만원</div>
      <div class="divider"></div>
      <div class="urgency">2026년 7월, 조건이 바뀝니다</div>
      <div class="cta">지금 상담 신청하기</div>
    </div>
  </div>
</body>
</html>
c           	        g d}d}d|  dd}ddt         igigdd	d
gid}|D ]1  }| d| d}t        d|        	 t        j                  |||d      }|j                  dv rt        d|j                   d       \|j                          |j                         }|j                  dg       }	|	st        d       |	d   j                  di       j                  dg       }
t        d |
D        d      }|t        d       t        j                  |d   d         }t        j                  |       t        dt         dt        |      dd         y! y## t        $ r}t        d"|        Y d}~Sd}~ww xY w)$u<   Gemini API로 배경 이미지 생성 후 BG_PATH에 저장.)z)gemini-2.0-flash-preview-image-generationzgemini-3-pro-image-previewzgemini-3.1-flash-image-previewz0https://generativelanguage.googleapis.com/v1betazBearer zapplication/json)AuthorizationzContent-TypepartstextresponseModalitiesIMAGETEXT)contentsgenerationConfigz/models/z:generateContentu   [배경] Gemini 모델 시도: x   )headersjsontimeout)i  i  u     → HTTP u   , 다음 모델로 시도...
candidatesu,     → candidates 없음, 다음 모델로...r   contentc              3  *   K   | ]  }d |v s|  yw)
inlineDataN ).0ps     I/home/jay/workspace/tools/ai-image-gen/_backup/gen_07_impact_number_v2.py	<genexpr>z&generate_background.<locals>.<genexpr>   s     EQ<13DqEs   	Nu2     → 이미지 파트 없음, 다음 모델로...r   datau     → 배경 저장:  (, bytes)Tu     → 오류: F)	BG_PROMPTprintrequestspoststatus_coderaise_for_statusr   getnextbase64	b64decodeBG_PATHwrite_byteslen	Exception)tokenmodelsapi_baser   payloadmodel_idurlrespr   r   r   
image_partimage_byteses                 r   generate_backgroundr8      s   zFAH #5'**G
  34561GV3DEG
  
(8*,<=/z:;	==gGSQD:-D$4$4#55QRS!!#99;D,3JDFqM%%i488"EEE%EtLJ!JL **:l+CF+KLK,)'"S5Ea4HPQ-6 	  	N1#&'	s,   A E ?E AEAE	E<#E77E<c                 .   ddl m}  t        j                  t	        t
              t        j                         rt	        t              nd      }t        j                  |d       t        dt                 |        5 }|j                  j                         }	 |j                  ddd	
      }|j                  dt        j                          d       |j!                  d       t"        j$                  j'                  dd       |j)                  t	        t"              d       t        dt"         dt"        j+                         j,                  dd       |j/                          	 ddd       y# |j/                          w xY w# 1 sw Y   yxY w)uF   HTML 오버레이를 Playwright로 캡처하여 SAMPLE_PATH에 저장.r   )sync_playwright )font_dirbg_pathzutf-8)encodingu   [HTML] 템플릿 저장: i8  )widthheight)viewportzfile://networkidle)
wait_untili  T)parentsexist_okpng)pathtypeu	   [캡처] r   r   r   N)playwright.sync_apir:   HTML_TEMPLATEformatstrFONT_DIRr*   exists	HTML_PATH
write_textr!   chromiumlaunchnew_pagegotoresolvewait_for_timeoutSAMPLE_PATHparentmkdir
screenshotstatst_sizeclose)r:   html_contentr   browserpages        r   capture_overlayra      sG   3 !''X ' 0Gb ( L 8	%i[
12		 a**##%		##tt-L#MDII	 1 1 345-IP!!$'$$TD$AOO[!1O>Ik]"[-=-=-?-G-G,J'RSMMO  MMO s%   >FCE6F6FFFc                    dd l } t        d       t        d       t        d       t        d       	 | j                         }t        dt        |       d       |r$t        d	       t        |      }|st        d
       nd}|st        d       t        d       t                t        j                  t        t               t        dt                t        d       t        d       t        dt                t        dt                t        d       y # t        $ r%}t        d|        t        d       d }Y d }~d }~ww xY w)Nr   z<============================================================u3   컨셉 #07 Impact Number v2 — hybrid-image 생성u   
[인증] 토큰 획득 중...u   [인증] 토큰 획득 성공 (z chars)u   [인증 실패] u;   [폴백] 배경 없이 단색 배경으로 진행합니다.u(   
[배경] Gemini 이미지 생성 중...u6   [배경] 모든 모델 실패 — 단색 배경 폴백FuH   [배경] CSS 단색 다크 배경 + 황금 글로우로 대체합니다.u,   
[캡처] HTML 오버레이 렌더링 중...u	   [복사] z=
============================================================u   생성 완료!z  sample-v2.png : z  07-impact-number-v2.png : )gcloud_authr!   get_access_tokenr,   r-   r8   ra   shutilcopy2rW   
FINAL_PATH)rc   r.   r7   bg_oks       r   mainri     s   	(O	
?@	(O 

+,,,./E
|7CD 9:#E*JK XY 

9: LLj)	Ij\
"#	/	
	{m
,-	(
56	(O?   $%KLs   (D 	E#EE__main__)r.   rL   returnbool)rk   None) __doc__
__future__r   r(   r   re   systimepathlibr   typingr   r"   __file__rX   
SCRIPT_DIRrG   insertrL   
OUTPUT_DIRr*   rW   rg   rO   homerM   r    rJ   r8   ra   ri   __name__r       r   <module>r{      s    #    
     (^""
 3z? #XY

)
)?*33
11	499;887 
aL)\8+\ zF rz   