
    (<iY                       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mZ ddl	m
Z
 ddlZddlmZ ddlmZmZmZmZmZmZ dZeZd	ZeZeZeZd
ZdZdZeZ ee      j@                  Z!edz  Z"edz  Z#e#dz  ddde#dz  ddde#dz  ddddZ$dZ%dZ&dZ'd)dZ(d*dZ)d+dZ*d+d Z+d+d!Z,d,d"Z-d-d#Z.d)d$Z/d)d%Z0d)d&Z1d' Z2e3d(k(  r e2        yy).uu   
컨셉 #24, #25, #26 하이브리드 이미지 생성 스크립트
Gemini Pro 배경 + Playwright HTML 오버레이
    )annotationsN)Path)Any)sync_playwright)CORE_METRIC_MIN_PX
CTA_MIN_PXHEADLINE_MIN_PXHEAD_SUB_RATIOSUBHEAD_MIN_PXWORKSPACE_ROOT   0   g?gffffff?g333333?ztools/ai-image-genzoutput/meta-ads/concept-catalogz24-apple-stylezPure clean off-white background #F5F5F7, extremely minimal, no objects, no texture, vast empty space, ultra clean studio lighting, Apple-inspired minimalism, 1080x1080, square formatapple)
output_dir	bg_promptstylez25-mcdonalds-stylezBold energetic background, top half bright vivid red #DA291C, bottom half golden yellow #FFC72C, diagonal split line between colors, cheerful and optimistic mood, high saturation, no text, no people, 1080x1080, square format	mcdonaldsz26-hyundai-stylea  Dark cinematic studio background, deep charcoal black #0D0F12, subtle metallic silver light streak coming from upper left corner, soft blue-tinted ambient glow on the edges, ultra-premium automotive aesthetic, no text, no objects, high contrast, 1080x1080, square formathyundai242526z0https://generativelanguage.googleapis.com/v1betazgemini-3-pro-image-previewzgemini-3.1-flash-image-previewc                    t         j                  j                  dt        t                     ddl} 	 | j                  d      }t        dt        |       d       |S # t        $ r}t        d| d       Y d}~nd}~ww xY w	 | j                  d      }|rd	| S n# t        $ r Y nw xY wddl}|j                  g d
ddd      }|j                  j                         }t        dt        |       d       |S )u5   인증 토큰 획득 (SA 우선, gcloud CLI fallback)r   Nz3https://www.googleapis.com/auth/generative-languageu$     [인증] SA 토큰 획득 성공 (z chars)u     [인증] SA 토큰 실패: u   , API 키 시도...GEMINI_API_KEYAPI_KEY:)gcloudauthzprint-access-tokenT)capture_outputtextchecku,     [인증] gcloud CLI 토큰 획득 성공 ()syspathinsertstrWORK_DIRgcloud_authget_service_account_tokenprintlen	Exceptionget_api_key
subprocessrunstdoutstrip)r&   tokeneapi_keyr,   results         V/home/jay/workspace/.worktrees/task-2057-dev2/tools/ai-image-gen/gen_concepts_24_26.pyget_auth_tokenr5   S   s   HHOOAs8}%F55A
 	4SZLHI F-aS0CDEEF))*:;gY''   ^^0$d  F MM!E	8UG
LMLs)   *A 	B 'A;;B B 	B)(B)c                   t        d|dd  d       | j                  d      r| dd }t         dt         d| }d	d
i}nt         dt         d}d|  d
d}dd|igigdddgid}	 t	        j
                  |||d      }|j                  dv rft        d|j                   d       | j                  d      rt         dt         d }nt         dt         d}t	        j
                  |||d      }|j                          |j                         }|j                  dg       }	|	st        d       y|	d   j                  di       j                  dg       }
t        d |
D        d      }|t        d       yt        j                  |d    d!         }|j                  |       t        |      d"z  }t        d#|j                    d$|d%d&       y'# t"        $ r}t        d(|        Y d}~yd}~ww xY w))u%   Gemini API로 배경 이미지 생성u     [배경생성] 프롬프트: NP   z...r      z/models/z:generateContent?key=Content-Typezapplication/jsonz:generateContentzBearer )Authorizationr9   partsr   responseModalitiesIMAGETEXT)contentsgenerationConfigx   )headersjsontimeout)i  i  u'     [배경생성] 모델 접근 실패 (u   ), fallback 시도...
candidatesu*     [배경생성] 오류: candidates 없음Fr   contentc              3  *   K   | ]  }d |v s|  yw)
inlineDataN ).0ps     r4   	<genexpr>z&generate_background.<locals>.<genexpr>   s     A|q/@1As   	u3     [배경생성] 오류: 이미지 데이터 없음rH   data   u     [배경생성] 완료:  (.0f KB)Tu     [배경생성] 오류: )r(   
startswithGEMINI_API_BASEMODEL_IDrequestspoststatus_codeFALLBACK_MODELraise_for_statusrC   getnextbase64	b64decodewrite_bytesr)   namer*   )r0   promptoutput_pathr2   urlrB   payloadresprM   rE   r;   
image_partimage_bytessize_kbr1   s                  r4   generate_backgroundrh   q   s7   	+F3BK=
<= 
#) !(3H	R!#56 !(3CD&ug..
  01231GV3DEG
!}}S'Mz);D<L<L;MMbcd
+().1AAVW^V_`().1AAQR==gGSQDyy{XXlB/
>@1!!)R044WbAAeA4H
GI&&z,'?'GH,k"T))+*:*:);2gc]$OP )!-.s'   (CG 5AG ;AG 	G4G//G4c                T    d|  dt          dt         dt         dt         dt         dS )z#24 Apple Style HTMLa  <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
  @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;600;700&display=swap');
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    width: 1080px;
    height: 1080px;
    overflow: hidden;
    background: #F5F5F7;
    font-family: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, sans-serif;
  }
  .container {
    width: 1080px;
    height: 1080px;
    position: relative;
    background-image: url('file://a  ');
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .content {
    text-align: center;
    padding: 0 120px;
  }
  .headline {
    font-size: z?px;
    font-weight: 600;
    color: #1D1D1F;
    line-height: zl;
    letter-spacing: -2px;
    white-space: pre-line;
    margin-bottom: 36px;
  }
  .sub {
    font-size: z?px;
    font-weight: 400;
    color: #86868B;
    line-height: z;
    letter-spacing: -1px;
    margin-bottom: 0;
  }
  .cta {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    font-size: u  px;
    font-weight: 400;
    color: #0066CC;
    letter-spacing: -0.5px;
    white-space: nowrap;
    text-decoration: none;
  }
</style>
</head>
<body>
<div class="container">
  <div class="content">
    <div class="headline">열심히는 하는데,<br>월급은 제자리걸음?</div>
    <div class="sub">이제 다른 방법을 찾아볼 때입니다</div>
  </div>
  <div class="cta">더 알아보기 →</div>
</div>
</body>
</html>)_HEADLINE_PX_LH_1_15_SUBHEAD_PX	_LH_RATIO_CTA_PXbg_paths    r4   build_apple_htmlrq      s\    #$ $+) , ~    }   	 y iF F    c                T    d|  dt          dt         dt         dt         dt         dS )z#25 McDonald's Style HTMLa  <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
  @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;700;900&display=swap');
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    width: 1080px;
    height: 1080px;
    overflow: hidden;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
  }
  .container {
    width: 1080px;
    height: 1080px;
    position: relative;
    background-image: url('file://a^  ');
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  .top-block {
    width: 100%;
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 60px 80px 30px;
  }
  .headline {
    font-size: z?px;
    font-weight: 900;
    color: #FFFFFF;
    line-height: a_  ;
    letter-spacing: -2px;
    text-align: center;
    white-space: pre-line;
    text-shadow: 2px 4px 12px rgba(0,0,0,0.3);
  }
  .bottom-block {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px 80px 60px;
    gap: 40px;
  }
  .sub {
    font-size: z?px;
    font-weight: 700;
    color: #292929;
    line-height: z;
    text-align: center;
    letter-spacing: -1px;
  }
  .cta-btn {
    background: #FFC72C;
    color: #292929;
    font-size: u  px;
    font-weight: 700;
    padding: 24px 80px;
    border-radius: 60px;
    letter-spacing: -0.5px;
    white-space: nowrap;
  }
</style>
</head>
<body>
<div class="container">
  <div class="top-block">
    <div class="headline">월급 제자리걸음?<br>이제 바꾸면 되잖아!</div>
  </div>
  <div class="bottom-block">
    <div class="sub">T.O.P 사업단과 함께 시작하세요</div>
    <div class="cta-btn">지금 시작하기</div>
  </div>
</div>
</body>
</html>)
_METRIC_PX_LH_1_1rl   _LH_1_2
_SIZE_48PXro   s    r4   build_mcdonalds_htmlrx      s\    #" $+) ," |   " }    | AT Trr   c                b    d|  dt          dt         dt         dt         dt         dt
         dS )	z#26 Hyundai Style HTMLa  <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
  @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;700;900&display=swap');
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body {
    width: 1080px;
    height: 1080px;
    overflow: hidden;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
  }
  .container {
    width: 1080px;
    height: 1080px;
    position: relative;
    background-image: url('file://ah  ');
    background-size: cover;
    background-position: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0;
  }
  .content {
    text-align: center;
    padding: 0 100px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 48px;
  }
  .eyebrow {
    font-size: zpx;
    font-weight: 300;
    color: #00D4FF;
    letter-spacing: 6px;
    text-transform: uppercase;
  }
  .headline {
    font-size: z?px;
    font-weight: 900;
    color: #F5F7FA;
    line-height: z;
    letter-spacing: -2px;
    white-space: pre-line;
    text-align: center;
  }
  .divider {
    width: 80px;
    height: 2px;
    background: #00D4FF;
  }
  .sub {
    font-size: z?px;
    font-weight: 300;
    color: #C0C8D0;
    line-height: z;
    letter-spacing: -0.5px;
    text-align: center;
  }
  .cta {
    position: absolute;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    border: 2px solid #00D4FF;
    color: #00D4FF;
    font-size: u  px;
    font-weight: 400;
    padding: 20px 72px;
    letter-spacing: 3px;
    text-transform: uppercase;
    white-space: nowrap;
  }
</style>
</head>
<body>
<div class="container">
  <div class="content">
    <div class="eyebrow">T.O.P 사업단</div>
    <div class="headline">열심히는 하는데,<br>월급은 제자리걸음?</div>
    <div class="divider"></div>
    <div class="sub">이제 변속할 시간입니다</div>
  </div>
  <div class="cta">T.O.P 확인하기</div>
</div>
</body>
</html>)
_SIZE_28PXrt   ru   rl   rm   rn   ro   s    r4   build_hyundai_htmlr{   R  sh    #" $+) ,$ |  |    }    y MZ Zrr   c                   |j                   dz  }|j                  | d       	 t               5 }|j                  j	                         }	 |j                  ddd      }|j                  d|j                          d	       |j                  d
       |j                   j                  dd       |j                  t        |      d       |j                         j                  dz  }t        d|j                   d|dd       	 |j!                          ddd       |j#                         r|j%                          yy# |j!                          w xY w# 1 sw Y   nxY wnE# t&        $ r9}t        d|        Y d}~|j#                         r|j%                          yyd}~ww xY w	 |j#                         r|j%                          yy# |j#                         r|j%                          w w xY w)u-   Playwright로 HTML을 1080x1080 PNG로 캡처z_overlay_temp.htmlzutf-8)encodingi8  )widthheight)viewportzfile://networkidle)
wait_untili  Tparentsexist_okpng)r"   typerN   u     [캡처] 완료: rO   rP   rQ   Nu     [캡처] 오류: F)parent
write_textr   chromiumlaunchnew_pagegotoresolvewait_for_timeoutmkdir
screenshotr$   statst_sizer(   r_   closeexistsunlinkr*   )html_contentra   	html_pathrK   browserpagerg   r1   s           r4   capture_html_to_pngr     s   ""%99I8 	 !jj'')G ''441P'Q		GI$5$5$7#89m	T %%d+""(((ES%5EB%**,44t;+K,<,<+=R}DQR	 (   	  	  	    #A3'( 	!	 (  9 s_   
E$ E
B=EEE$ EEE E$ #G $	F&-F!;G !F&&G #G/c           	        t         |    }|d   }|j                  dd       |dz  }|dz  }|d   }t        dd        t        d	|  d
       t        d        t        j                         }t	        ||d   |      }|r|}	nt        d       d}	|dk(  r|	rt        |	      }
nVt               }
nK|dk(  r|	rt        |	      }
n8t               }
n-|dk(  r|	rt        |	      }
nt               }
nt        d|        yt        |
|      }|j                         r|j                          t        j                         |z
  }|rt        d	|  d| d|dd       |S t        d	|  d|dd       |S )u   단일 컨셉 이미지 생성r   Tr   zbg_temp.jpg
sample.pngr   
<============================================================u	   [컨셉 #u   ] 생성 시작r   u7     [배경] 배경 생성 실패, 단색 fallback 사용Nr   r   r   u%     [오류] 알 수 없는 스타일: Fu
   ] 완료: rO   z.1fu   초)u
   ] 실패 ()CONCEPTSr   r(   timerh   rq   build_apple_html_solidrx   build_mcdonalds_html_solidr{   build_hyundai_html_solidr   r   r   )
concept_idr0   cfgr   rp   sample_pathr   startbg_okbg_for_htmlhtmlokelapseds                r4   generate_conceptr     s   
:
C<(JTD1=(G|+KLE	Bvh-	Ij\
12	VHIIKE  s;'7AE 	GI #K0D)+D	+	'4D-/D	)	%k2D+-D5eW=> 
T;	/B ~~iikE!G		*Z}Bwsm4PQ I 		*Z}DABIrr   c                      y)u*   Apple Style - 순수 CSS 배경 (fallback)u  <!DOCTYPE html>
<html><head><meta charset="UTF-8">
<style>
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body { width: 1080px; height: 1080px; overflow: hidden;
    font-family: 'Pretendard', 'Noto Sans KR', -apple-system, sans-serif; }
  .container { width: 1080px; height: 1080px; position: relative;
    background: #F5F5F7; display: flex; flex-direction: column;
    align-items: center; justify-content: center; }
  .headline { font-size: {_HEADLINE_PX}px; font-weight: 600; color: #1D1D1F;
    line-height: {_LH_1_15}; letter-spacing: -2px; text-align: center;
    margin-bottom: 36px; }
  .sub { font-size: {_SUBHEAD_PX}px; font-weight: 400; color: #86868B;
    line-height: {_LH_RATIO}; letter-spacing: -1px; text-align: center; }
  .cta { position: absolute; bottom: 80px; left: 50%; transform: translateX(-50%);
    font-size: {_CTA_PX}px; color: #0066CC; white-space: nowrap; }
</style></head><body>
<div class="container">
  <div class="headline">열심히는 하는데,<br>월급은 제자리걸음?</div>
  <div class="sub">이제 다른 방법을 찾아볼 때입니다</div>
  <div class="cta">더 알아보기 →</div>
</div></body></html>rI   rI   rr   r4   r   r     s    rr   c                      y)u/   McDonald's Style - 순수 CSS 배경 (fallback)u  <!DOCTYPE html>
<html><head><meta charset="UTF-8">
<style>
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body { width: 1080px; height: 1080px; overflow: hidden;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif; }
  .container { width: 1080px; height: 1080px; position: relative;
    display: flex; flex-direction: column; }
  .top-block { flex: 1; background: #DA291C; display: flex;
    align-items: center; justify-content: center; padding: 60px 80px 30px; }
  .headline { font-size: {_METRIC_PX}px; font-weight: 900; color: #FFFFFF;
    line-height: {_LH_1_1}; letter-spacing: -2px; text-align: center; }
  .bottom-block { flex: 1; background: #FFC72C; display: flex;
    flex-direction: column; align-items: center; justify-content: center;
    padding: 20px 80px 60px; gap: 40px; }
  .sub { font-size: {_SUBHEAD_PX}px; font-weight: 700; color: #292929;
    text-align: center; letter-spacing: -1px; }
  .cta-btn { background: #FFC72C; border: 4px solid #292929; color: #292929;
    font-size: {_SIZE_48PX}px; font-weight: 700; padding: 24px 80px;
    border-radius: 60px; }
</style></head><body>
<div class="container">
  <div class="top-block">
    <div class="headline">월급 제자리걸음?<br>이제 바꾸면 되잖아!</div>
  </div>
  <div class="bottom-block">
    <div class="sub">T.O.P 사업단과 함께 시작하세요</div>
    <div class="cta-btn">지금 시작하기</div>
  </div>
</div></body></html>rI   rI   rr   r4   r   r   .  s    rr   c                      y)u,   Hyundai Style - 순수 CSS 배경 (fallback)uv  <!DOCTYPE html>
<html><head><meta charset="UTF-8">
<style>
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body { width: 1080px; height: 1080px; overflow: hidden;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif; }
  .container { width: 1080px; height: 1080px; position: relative;
    background: #0D0F12; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 0; }
  .content { text-align: center; padding: 0 100px; display: flex;
    flex-direction: column; align-items: center; gap: 48px; }
  .eyebrow { font-size: {_SIZE_28PX}px; font-weight: 300; color: #00D4FF;
    letter-spacing: 6px; text-transform: uppercase; }
  .headline { font-size: {_METRIC_PX}px; font-weight: 900; color: #F5F7FA;
    line-height: {_LH_1_1}; letter-spacing: -2px; text-align: center; }
  .divider { width: 80px; height: 2px; background: #00D4FF; }
  .sub { font-size: {_SUBHEAD_PX}px; font-weight: 300; color: #C0C8D0;
    line-height: {_LH_RATIO}; text-align: center; }
  .cta { position: absolute; bottom: 80px; left: 50%;
    transform: translateX(-50%); border: 2px solid #00D4FF;
    color: #00D4FF; font-size: {_CTA_PX}px; font-weight: 400;
    padding: 20px 72px; letter-spacing: 3px; text-transform: uppercase;
    white-space: nowrap; }
</style></head><body>
<div class="container">
  <div class="content">
    <div class="eyebrow">T.O.P 사업단</div>
    <div class="headline">열심히는 하는데,<br>월급은 제자리걸음?</div>
    <div class="divider"></div>
    <div class="sub">이제 변속할 시간입니다</div>
  </div>
  <div class="cta">T.O.P 확인하기</div>
</div></body></html>rI   rI   rr   r4   r   r   P  s     rr   c            	     n   dd l } | j                  d      }|j                  dg dd       |j                         }t	        d       t	        d	       t	        d       	 t               }|j                  dk(  rg dn|j                  g}i }|D ]  }t        ||      }|||<    t	        d       t	        d       t	        d       |j                         D ].  \  }}|rdnd}	t        |   d   dz  }
t	        d| d|	 d|
        0 y # t        $ r%}t	        d
|        t	        d       d }Y d }~d }~ww xY w)Nr   u/   컨셉 #24~#26 하이브리드 이미지 생성)descriptionz	--concept)r   r   r   allr   )choicesdefaultr   uB   컨셉 이미지 생성 시작 (Gemini 배경 + HTML 오버레이)u   [오류] 인증 실패: u5   [fallback] CSS 단색 배경으로 진행합니다...r   z=
============================================================u   생성 결과u   성공u   실패r   r   z  #z: u    → )argparseArgumentParseradd_argument
parse_argsr(   r5   r*   conceptr   itemsr   )r   parserargsr0   r1   conceptsresultscidr   statusr"   s              r4   mainr   y  s?   $$1b$cF
-FPUVD	(O	
NO	(O  &*\\U%:!HG c5) 
/	/	(O==? 0RX}\*\9C56(%v./0  (,-EFs   
D 	D4D//D4__main__)returnr$   )r0   r$   r`   r$   ra   r   r   bool)rp   r   r   r$   )r   r$   ra   r   r   r   )r   r$   r0   r$   r   r   )4__doc__
__future__r   r\   rC   r!   r   pathlibr   typingr   rU   playwright.sync_apir   
gen_configr   r   r	   r
   r   r   rz   rn   rw   rl   rj   rt   ru   rk   rv   rm   __file__r   BASE_DIRr%   OUTPUT_BASEr   rS   rT   rX   r5   rh   rq   rx   r{   r   r   r   r   r   r   __name__rI   rr   r4   <module>r      sH  
 #   
     / v v 





	 >  00@@ "$44B  "$88'
 	 "$666 
)J E'1<6zHVVr\FD:z4D"R0D zF rr   