
    i:8                    j   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	Z	ddl
mZ  ee      j                  Z ed      Zej!                  dd       ed	z  Zed
z  Zedz  Zedz  ZdZdZdZdZej2                  j5                  d ee             ddlZddZddZddZd Z e!dk(  r e         yy)u   
컨셉 #32 삼성화재 스타일 하이브리드 이미지 생성기
Gemini AI 배경 + HTML 텍스트 오버레이 → 최종 합성 이미지
    )annotationsN)Path)sync_playwrightzH/home/jay/workspace/output/meta-ads/concept-catalog/32-samsungfire-styleT)parentsexist_okzbg_gemini.jpgztemplate.htmlz
sample.pngz32-samsungfire-style.pnga4  Clean minimal office environment background, bright natural daylight through large windows, soft spring morning atmosphere, white desks and workstations with subtle blue accents, professional Korean corporate office interior, upper floor city view partially visible, abstract upward growth chart elements subtly integrated into environment, color palette: predominantly white and very pale sky blue (#EAF6FB tones), no people, no text, no faces, photorealistic high quality, 1080x1080 pixels, clean modern Korean corporate aesthetic, hopeful and premium atmospherez0https://generativelanguage.googleapis.com/v1betazgemini-3-pro-image-previewzgemini-3.1-flash-image-previewc                    t        d       t        j                         } dd|  d}ddt        igigddd	gid
}t        t
        fD ]r  }t         d| d}t        d|        t        d      D ]F  }	 t        j                  |||d      }|j                  dk(  r|j                         }|j                  dg       }|r|d   j                  di       j                  dg       }	|	D ]b  }
d|
v st        j                  |
d   d         }t        j!                  |       t        dt         dt#        |      dd       t        c c c S  t        dt%        |j'                                       n(t        d|j                   d|j(                  dd         |d k  s2t-        j.                  d"       I u t1        d#      # t*        $ r}t        d|d z    d!|        Y d}~Od}~ww xY w)$uK   Gemini API로 배경 이미지를 생성합니다. SA 토큰 우선 사용.u+   [1/3] Gemini 배경 이미지 생성 중...zapplication/jsonzBearer )zContent-TypeAuthorizationpartstextresponseModalitiesIMAGETEXT)contentsgenerationConfigz/models/z:generateContentu     모델 시도:    x   )headersjsontimeout   
candidatesr   content
inlineDatadatau     배경 이미지 저장: z (,z bytes)u     응답 구조 이상: u     API 오류 z: Nu	     시도    u	    실패:    u   Gemini 배경 생성 실패)printgcloud_authget_service_account_tokenGEMINI_PROMPTMODEL_IDFALLBACK_MODEL_IDGEMINI_API_BASErangerequestspoststatus_coder   getbase64	b64decodeBG_PATHwrite_byteslenlistkeysr   	ExceptiontimesleepRuntimeError)tokenr   payloadmodelurlattemptrespr   r   r
   partimg_dataes                e/home/jay/workspace/.worktrees/task-2116-dev1/tools/ai-image-gen/_backup/gen_concept32_samsungfire.pygenerate_backgroundr?   /   s   	
78 113E*"5'*G ]+
 2GV3DE	G -.  !%0@A!%)*Qx 	G;}}S'QTU##s*99;D!%,!;J! *1 1 1)R @ D DWb Q$) /D+t3+1+;+;D<Nv<V+W ' 3 3H = %(CG9BsS[}]^N__f&g h'./ 4T$))+5F4GHIM$*:*:);2diio=NOP {

1)	2 4
55  ;	'!)IaS9::;s'   5A:G0AGAG	G/G**G/c                    t        d       | j                         }d| d}t        j                  |d       t        dt                t        S )u9   HTML 텍스트 오버레이 템플릿을 생성합니다.u9   [2/3] HTML 텍스트 오버레이 템플릿 생성 중...u	  <!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=1080">
<title>컨셉 #32 삼성화재 스타일</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet">
<style>
  @font-face {
    font-family: 'Pretendard';
    src: local('Pretendard-Black'),
         url('/home/jay/.local/share/fonts/Pretendard/Pretendard-Black.otf') format('opentype');
    font-weight: 900;
    font-style: normal;
  }
  @font-face {
    font-family: 'Pretendard';
    src: local('Pretendard-ExtraBold'),
         url('/home/jay/.local/share/fonts/Pretendard/Pretendard-ExtraBold.otf') format('opentype');
    font-weight: 800;
    font-style: normal;
  }
  @font-face {
    font-family: 'Pretendard';
    src: local('Pretendard-Bold'),
         url('/home/jay/.local/share/fonts/Pretendard/Pretendard-Bold.otf') format('opentype');
    font-weight: 700;
    font-style: normal;
  }
  @font-face {
    font-family: 'Pretendard';
    src: local('Pretendard-SemiBold'),
         url('/home/jay/.local/share/fonts/Pretendard/Pretendard-SemiBold.otf') format('opentype');
    font-weight: 600;
    font-style: normal;
  }
  @font-face {
    font-family: 'Pretendard';
    src: local('Pretendard-Medium'),
         url('/home/jay/.local/share/fonts/Pretendard/Pretendard-Medium.otf') format('opentype');
    font-weight: 500;
    font-style: normal;
  }
  @font-face {
    font-family: 'Pretendard';
    src: local('Pretendard-Regular'),
         url('/home/jay/.local/share/fonts/Pretendard/Pretendard-Regular.otf') format('opentype');
    font-weight: 400;
    font-style: normal;
  }
  @font-face {
    font-family: 'Pretendard';
    src: local('Pretendard-Light'),
         url('/home/jay/.local/share/fonts/Pretendard/Pretendard-Light.otf') format('opentype');
    font-weight: 300;
    font-style: normal;
  }

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

  body {
    width: 1080px;
    height: 1080px;
    overflow: hidden;
    background: #EAF6FB;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
  }

  .canvas {
    position: relative;
    width: 1080px;
    height: 1080px;
    overflow: hidden;
  }

  /* 배경 이미지 레이어 */
  .bg-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 1080px;
    height: 1080px;
    background-image: url('u  ');
    background-size: cover;
    background-position: center;
  }

  /* 반투명 오버레이 — 텍스트 가독성 확보 */
  .bg-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 1080px;
    height: 1080px;
    background: rgba(234, 246, 251, 0.78);
  }

  /* ── 상단 악센트 라인 ── */
  .accent-line-top {
    position: absolute;
    top: 108px;
    left: 0;
    width: 1080px;
    height: 3px;
    background: #5BC2E7;
  }

  /* ── 상단 바 ── */
  .top-bar {
    position: absolute;
    top: 60px;
    left: 72px;
    right: 72px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }

  .top-left {
    font-size: 40px;
    font-weight: 400;
    color: #003CDC;
    letter-spacing: 0.08em;
    line-height: 1;
  }

  .top-right {
    font-size: 40px;
    font-weight: 400;
    color: #003CDC;
    letter-spacing: 0.03em;
    line-height: 1;
    text-align: right;
  }

  /* ── 메인 헤드라인 블록 ── */
  .headline-block {
    position: absolute;
    top: 148px;
    left: 72px;
    right: 72px;
  }

  .headline-line1 {
    font-size: 96px;
    font-weight: 800;
    color: #003CDC;
    letter-spacing: -0.01em;
    line-height: 1.2;
    margin-bottom: 4px;
  }

  .headline-number {
    font-size: 120px;
    font-weight: 900;
    color: #003CDC;
    letter-spacing: -0.02em;
    line-height: 1.1;
    margin-bottom: 0px;
  }

  .headline-line3 {
    font-size: 96px;
    font-weight: 800;
    color: #003CDC;
    letter-spacing: -0.01em;
    line-height: 1.2;
  }

  /* ── 중간 악센트 바 ── */
  .accent-bar-mid {
    position: absolute;
    top: 610px;
    left: 72px;
    width: 260px;
    height: 5px;
    background: #5BC2E7;
    border-radius: 3px;
  }

  /* ── 서브 헤드라인 ── */
  .sub-headline {
    position: absolute;
    top: 636px;
    left: 72px;
    right: 72px;
    font-size: 64px;
    font-weight: 600;
    color: #003CDC;
    letter-spacing: -0.005em;
    line-height: 1.3;
  }

  /* ── 배지 행 ── */
  .badge-row {
    position: absolute;
    top: 730px;
    left: 72px;
    right: 72px;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
  }

  .badge {
    background: #5BC2E7;
    color: #FFFFFF;
    font-size: 40px;
    font-weight: 700;
    padding: 14px 32px;
    border-radius: 24px;
    display: inline-block;
    letter-spacing: 0.02em;
    line-height: 1;
    white-space: nowrap;
  }

  /* ── CTA 버튼 ── */
  .cta-wrapper {
    position: absolute;
    top: 840px;
    left: 72px;
  }

  .cta-button {
    background: #5BC2E7;
    color: #003CDC;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-size: 44px;
    font-weight: 700;
    padding: 22px 64px;
    border-radius: 30px;
    border: none;
    letter-spacing: 0.04em;
    display: inline-block;
    line-height: 1;
    white-space: nowrap;
  }

  /* ── 하단 악센트 라인 ── */
  .accent-line-bottom {
    position: absolute;
    top: 1000px;
    left: 0;
    width: 1080px;
    height: 3px;
    background: #5BC2E7;
  }

  /* ── 하단 푸터 텍스트 ── */
  .footer-text {
    position: absolute;
    top: 1022px;
    left: 72px;
    right: 72px;
    font-size: 40px;
    font-weight: 300;
    color: rgba(0, 61, 220, 0.70);
    letter-spacing: 0.03em;
    line-height: 1.3;
    white-space: nowrap;
  }
</style>
</head>
<body>
<div class="canvas">

  <!-- 배경 이미지 -->
  <div class="bg-image"></div>

  <!-- 반투명 오버레이 -->
  <div class="bg-overlay"></div>

  <!-- 상단 악센트 라인 -->
  <div class="accent-line-top"></div>

  <!-- 상단 바: T.O.P 사업단 / #1 성장 조직 -->
  <div class="top-bar">
    <div class="top-left">T.O.P 사업단</div>
    <div class="top-right">#1 성장 조직 · 코스닥 상장 인카금융</div>
  </div>

  <!-- 메인 헤드라인 블록 -->
  <div class="headline-block">
    <div class="headline-line1">당신이 머무르는 동안,</div>
    <div class="headline-number">매출 1,863%</div>
    <div class="headline-line3">성장했습니다</div>
  </div>

  <!-- 중간 악센트 바 -->
  <div class="accent-bar-mid"></div>

  <!-- 서브 헤드라인 -->
  <div class="sub-headline">판을 바꾸는 전략, T.O.P 사업단</div>

  <!-- 배지 행 -->
  <div class="badge-row">
    <span class="badge">482명 → 5,500명 성장</span>
    <span class="badge">신입 최대 1,000만원</span>
  </div>

  <!-- CTA 버튼 -->
  <div class="cta-wrapper">
    <div class="cta-button">지금 지원하기 →</div>
  </div>

  <!-- 하단 악센트 라인 -->
  <div class="accent-line-bottom"></div>

  <!-- 하단 푸터 텍스트 -->
  <div class="footer-text">상위 1%의 영업 로직을 배우다 · 대체 불가능한 전문가</div>

</div>
</body>
</html>zutf-8)encodingu     HTML 템플릿 저장: )r   as_uriTEMPLATE_PATH
write_text)bg_pathbg_urihtmls      r>   build_html_templaterH   c   s`    	
EF^^FXp #8 i$qADF
 TG4	%m_
56    c           	        t        d       t               5 }|j                  j                  dg d      }|j	                  dddd      }|j                         }|j                  d	|  d
d       |j                  d       |j                  d       |j                  t        t              dddddd       |j                          ddd       t        dt                t        S # 1 sw Y   !xY w)uQ   Playwright로 HTML을 렌더링하여 최종 합성 이미지를 캡처합니다.u2   [3/3] Playwright로 최종 이미지 캡처 중...T)z--no-sandboxz--disable-setuid-sandboxz--disable-dev-shm-usage)headlessargsi8  )widthheightr   )viewportdevice_scale_factorzfile://networkidlei0u  )
wait_untilr   z() => document.fonts.readyi  r   )xyrM   rN   png)pathcliptypeNu     최종 이미지 저장: )r   r   chromiumlaunchnew_contextnew_pagegotoevaluatewait_for_timeout
screenshotstrSAMPLE_PATHclose)template_pathpbrowsercontextpages        r>   capture_compositeri     s    	
>?		 a**##X $ 
 %%#t4 ! & 
 ! 			GM?+u	U 	23d# 	[!q44@ 	 	
 	36 
'}
569 s   B5C++C4c                    t        d       t        d       t        d       t        j                         } t               }t        |      }t	        |      }t        j                  |t               t        dt                t        j                         | z
  }t        d|dd       t        dt                t        dt                t        d	|        y )
Nz<============================================================uB   컨셉 #32 삼성화재 스타일 하이브리드 이미지 생성u     복사 완료: u   
완료! 소요 시간: z.1fu   초u     sample.png  → u     32-samsungfire-style.png → u     template.html → )	r   r2   r?   rH   ri   shutilcopy2
FINAL_PATHrb   )startrE   rd   sample_pathelapseds        r>   mainrq     s    	(O	
NO	(OIIKE "#G (0M $M2K LLj)	j\
*+iikE!G	%gc]#
67	{m
,-	+J<
89	 
01rI   __main__)returnr   )rE   r   rs   r   )rd   r   rs   r   )"__doc__
__future__r   r*   rk   sysr2   pathlibr   r&   playwright.sync_apir   __file__parent
SCRIPT_DIR
OUTPUT_DIRmkdirr,   rC   rb   rm   r!   r$   r"   r#   rV   insertra   r   r?   rH   ri   rq   __name__ rI   r>   <module>r      s   
 #   
    / (^""
\]
 
    -

&_,<'44
N  E'4  3z? # /6hK`
 J26 zF rI   