
    i4              
       .   d Z ddlZddlZddlmZ ddlZddlmZ ej                  j                  d e
 ee      j                               ddlZ ed      Zedz  Zedz  Zedz  Zd	Zd
ZdZdZdZdefdZde
dedededef
dZd Zedk(  r e        yy)u   GA 배너 M2-2 '관리자 비전' 세트 — 2장 생성
  1. ga-leader-1200x628.png  (가로형)
  2. ga-leader-1080x1080.png (정사각형)
컨셉 #45 금융 럭셔리 + GA 그린 적용
    N)Path)sync_playwrightz-/home/jay/workspace/output/google-ads/bannerszga-leader-1200x628.pngzga-leader-1080x1080.pngzga_leader_bg.jpgz0https://generativelanguage.googleapis.com/v1betaz.file:///home/jay/.local/share/fonts/Pretendardu  A person standing in front of a whiteboard in a wide open modern office, seen from behind, drawing a simple org chart or strategy diagram. Bright natural daylight, clean minimalist office environment. The person is wearing smart business casual attire. The whiteboard shows clean lines and boxes – an organizational chart. Wide-angle photorealistic scene conveying leadership and planning. Soft natural light through large windows, neutral tones. Professional business photography quality. No text, no watermarks.u  <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
  @font-face {{
    font-family: 'Pretendard';
    src: url('{font_dir}/Pretendard-Bold.otf') format('opentype');
    font-weight: 700;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('{font_dir}/Pretendard-Medium.otf') format('opentype');
    font-weight: 500;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('{font_dir}/Pretendard-SemiBold.otf') format('opentype');
    font-weight: 600;
  }}
  * {{ margin: 0; padding: 0; box-sizing: border-box; }}
  body {{
    width: 1200px;
    height: 628px;
    overflow: hidden;
    background: #1a2a1a;
  }}
  .container {{
    position: relative;
    width: 1200px;
    height: 628px;
    overflow: hidden;
  }}
  /* 배경 이미지 — 우측 45% */
  .bg-image {{
    position: absolute;
    top: 0;
    right: 0;
    width: 54%;
    height: 100%;
    background-image: url('{bg_path}');
    background-size: cover;
    background-position: center right;
  }}
  /* 우측 이미지 위에 얇은 투명 오버레이만 (피사체 보호) */
  .bg-image::after {{
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(
      to right,
      rgba(240,245,240,0.55) 0%,
      rgba(240,245,240,0.1) 35%,
      rgba(240,245,240,0.0) 100%
    );
  }}
  /* 좌측 텍스트 패널 — 55% */
  .left-panel {{
    position: absolute;
    top: 0;
    left: 0;
    width: 55%;
    height: 100%;
    background: rgba(248,250,248,0.82);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 52px 56px;
  }}
  /* 상단 레이블 */
  .label {{
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-size: 22px;
    font-weight: 600;
    color: #00897B;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    margin-bottom: 18px;
  }}
  /* 헤드라인 */
  .headline {{
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-size: 46px;
    font-weight: 700;
    color: #1a2a1a;
    line-height: 1.25;
    letter-spacing: -0.02em;
    margin-bottom: 20px;
  }}
  /* 구분선 */
  .divider {{
    width: 56px;
    height: 4px;
    background: #2E7D32;
    border-radius: 2px;
    margin-bottom: 20px;
  }}
  /* 서브텍스트 */
  .sub {{
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-size: 24px;
    font-weight: 500;
    color: #78909C;
    letter-spacing: 0.04em;
    margin-bottom: 36px;
  }}
  /* CTA 버튼 */
  .cta-btn {{
    display: inline-block;
    background: #2E7D32;
    color: #FFFFFF;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-size: 22px;
    font-weight: 700;
    padding: 16px 36px;
    border-radius: 4px;
    letter-spacing: 0.03em;
    white-space: nowrap;
    width: fit-content;
  }}
</style>
</head>
<body>
<div class="container">
  <!-- 배경 이미지 (우측) -->
  <div class="bg-image"></div>

  <!-- 좌측 텍스트 패널 -->
  <div class="left-panel">
    <div class="label">GA Manager Path</div>
    <div class="headline">GA 지점장,<br>가장 빠른 경로 안내</div>
    <div class="divider"></div>
    <div class="sub">교육 &nbsp;|&nbsp; 인프라 &nbsp;|&nbsp; 운영 지원</div>
    <div class="cta-btn">지점장 경로 확인</div>
  </div>
</div>
</body>
</html>
uO  <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
  @font-face {{
    font-family: 'Pretendard';
    src: url('{font_dir}/Pretendard-Bold.otf') format('opentype');
    font-weight: 700;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('{font_dir}/Pretendard-Medium.otf') format('opentype');
    font-weight: 500;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('{font_dir}/Pretendard-SemiBold.otf') format('opentype');
    font-weight: 600;
  }}
  @font-face {{
    font-family: 'Pretendard';
    src: url('{font_dir}/Pretendard-ExtraBold.otf') format('opentype');
    font-weight: 800;
  }}
  * {{ margin: 0; padding: 0; box-sizing: border-box; }}
  body {{
    width: 1080px;
    height: 1080px;
    overflow: hidden;
    background: #1a2a1a;
  }}
  .container {{
    position: relative;
    width: 1080px;
    height: 1080px;
    overflow: hidden;
  }}
  /* 전체 배경 이미지 */
  .bg-image {{
    position: absolute;
    inset: 0;
    background-image: url('{bg_path}');
    background-size: cover;
    background-position: center;
  }}
  /* 라이트 그린 그라데이션 오버레이: 상단→하단 밝아지는 방향 */
  /* 텍스트 가독성 위해 상단에 더 진한 처리, 하단은 밝게 */
  .overlay {{
    position: absolute;
    inset: 0;
    background: linear-gradient(
      to bottom,
      rgba(28, 56, 28, 0.72) 0%,
      rgba(40, 72, 40, 0.58) 30%,
      rgba(60, 100, 60, 0.38) 60%,
      rgba(200, 230, 200, 0.22) 100%
    );
  }}
  /* 텍스트 영역 */
  .content {{
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: space-between;
    padding: 72px 64px 76px;
  }}
  /* 상단 헤드라인 블록 */
  .top-block {{
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex: 0 0 auto;
    padding-top: 16px;
  }}
  .label {{
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-size: 26px;
    font-weight: 600;
    color: rgba(200, 240, 200, 0.9);
    letter-spacing: 0.14em;
    text-transform: uppercase;
    margin-bottom: 22px;
  }}
  .headline {{
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-size: 58px;
    font-weight: 800;
    color: #FFFFFF;
    line-height: 1.22;
    letter-spacing: -0.02em;
    text-align: center;
    text-shadow: 0 2px 16px rgba(0,0,0,0.45);
  }}
  /* 중앙 지원 사항 */
  .mid-block {{
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    flex: 0 0 auto;
  }}
  .divider {{
    width: 64px;
    height: 4px;
    background: #A5D6A7;
    border-radius: 2px;
    margin-bottom: 28px;
  }}
  .support-list {{
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-size: 30px;
    font-weight: 500;
    color: rgba(255,255,255,0.92);
    letter-spacing: 0.06em;
    text-align: center;
    text-shadow: 0 1px 8px rgba(0,0,0,0.4);
    line-height: 1.5;
  }}
  /* 하단 CTA */
  .bottom-block {{
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 0 0 auto;
  }}
  .cta-btn {{
    display: inline-block;
    background: #2E7D32;
    color: #FFFFFF;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    font-size: 28px;
    font-weight: 700;
    padding: 20px 56px;
    border-radius: 4px;
    letter-spacing: 0.04em;
    text-align: center;
    box-shadow: 0 4px 20px rgba(46, 125, 50, 0.5);
  }}
</style>
</head>
<body>
<div class="container">
  <div class="bg-image"></div>
  <div class="overlay"></div>
  <div class="content">
    <!-- 상단 헤드라인 -->
    <div class="top-block">
      <div class="label">GA Manager Path</div>
      <div class="headline">GA 지점장,<br>가장 빠른 경로 안내</div>
    </div>
    <!-- 중앙 지원 사항 -->
    <div class="mid-block">
      <div class="divider"></div>
      <div class="support-list">교육 &nbsp;|&nbsp; 인프라 &nbsp;|&nbsp; 운영 지원</div>
    </div>
    <!-- 하단 CTA -->
    <div class="bottom-block">
      <div class="cta-btn">지점장 경로 확인</div>
    </div>
  </div>
</div>
</body>
</html>
returnc            
      N   	 t        j                  d      } d|  dd	}g d
}|D ]t  }t
         d| d}ddt        igigdddgid}t        d| d       	 t        j                  |||d      }|j                  dk(  r|j                         }	|	j                  di g      d   j                  di       j                  dg       D ]Y  }
d|
v st        j                  |
d   d         }t        j                  |       t        dt         dt!        |      d d!         y" |	j                  di g      d   j                  d#d$      }t        d%|        t        d&t#        |	      dd'         Mt        d(|j                   d)|j$                  dd*         w y# t        $ rX}t        d| d       	 t        j                         } n(# t        $ r}t        d|        Y d}~Y d}~yd}~ww xY wY d}~d}~ww xY w# t        $ r}t        d|        Y d}~d}~ww xY w)+u2   Gemini API로 배경 이미지를 생성합니다.z3https://www.googleapis.com/auth/generative-languageu     [SA 토큰 오류] u    — ADC/gcloud 시도u     [인증 실패] NFzBearer zapplication/json)AuthorizationzContent-Type)zgemini-3.1-flash-image-previewzgemini-3-pro-image-previewzgemini-2.5-flash-imagez/models/z:generateContentpartstextresponseModalitiesTEXTIMAGE)contentsgenerationConfigu'     배경 생성 요청 중... (모델: )x   )headersjsontimeoutu     [연결 오류]    
candidatesr   content
inlineDatadatau     배경 저장 완료:  (,z bytes)TfinishReason?u)     [이미지 파트 없음] finishReason=u     응답 일부: i  z  [HTTP z] i,  )gcloud_authget_service_account_token	Exceptionprintget_access_tokenGEMINI_API_BASE	BG_PROMPTrequestspoststatus_coder   getbase64	b64decodeBG_PATHwrite_byteslenstrr	   )sa_tokenee2r   modelsmodelurlpayloadrespr   part	img_bytesreasons                a/home/jay/workspace/.worktrees/task-2116-dev1/tools/ai-image-gen/_backup/gen_ga_leader_banners.pygenerate_backgroundr:   _  s]   
88A
 #*( 4FXYGF
  D !%0@A!VY$7#89:!57H I
 	7wa@A	==gGSQD s"99;Dt,Q/Y#Wb!	 
  4' & 0 0l1CF1K LI''	24WIRIq?QQXYZ	  XXlRD1!488MF=fXFG%c$io%678HT--.b4C0ABC9D: W  %aS(>?@	"335H 	&rd+,5	 .  	&qc*+	sY   F H	G?'G:7GG:	G1G,#G:,G11G::G?	H$HH$html_contentoutput_pathwidthheightc                    t         d| d| dz  }|j                  | d       t               5 }|j                  j	                         }|j                  ||d      }|j                  d|        |j                  d	       |j                  t        |      d
       |j                          ddd       |j                         j                  dz  }t        d| d|dd       y# 1 sw Y   :xY w)u-   Playwright로 HTML을 PNG로 캡처합니다.overlay_xz.htmlzutf-8)encoding)r=   r>   )viewportfile://i	  png)pathtypeNi   u     PNG 저장 완료: r   z.0fz KB)T)WORK_DIR
write_textr   chromiumlaunchnew_pagegotowait_for_timeout
screenshotr-   closestatst_sizer    )	r;   r<   r=   r>   	html_filepbrowserpagesize_kbs	            r9   render_htmlrX     s    XeWAfXU;;I8		 a**##%5F)KL		GI;'(d#S-E:  ((4/G	!+bT
BC s   BC((C1c                  :   t         j                  dd       t        d       t        d       t        d       t        d       t        d       t               } | rdt         }t        d       nt        d	       d
}t        d       t
        j                  t        |      }t        |t        dd       t        d       t        j                  t        |      }t        |t        dd       t        d       t        dt                t        dt                y )NT)parentsexist_okz<============================================================u/   GA 배너 M2-2 '관리자 비전' 세트 생성u'   컨셉 #45 금융 럭셔리 + GA 그린u(   
[1/3] Gemini 배경 이미지 생성...rD   u     배경 생성 성공u>     [경고] 배경 생성 실패 — 컬러 폴백으로 진행 u-   
[2/3] 1200x628 가로형 배너 렌더링...)font_dirbg_pathi  it  u1   
[3/3] 1080x1080 정사각형 배너 렌더링...i8  u   
완료!z  1200x628 : z  1080x1080: )rH   mkdirr    r:   r*   HTML_1200x628formatFONT_DIRrX   OUTPUT_1200x628HTML_1080x1080OUTPUT_1080x1080)bg_okbg_url	html_widehtml_sqs       r9   mainrj     s    NN4$N/	(O	
;<	
34	(O 

56!E7)$&'NO 

:;$$h$GI	?D#6 

>?##Xv#FG)46	+	M/*
+,	M*+
,-    __main__)__doc__r(   syspathlibr   r$   playwright.sync_apir   rF   insertr-   __file__parentr   rH   rc   re   r*   r"   rb   r#   r`   rd   boolr:   intrX   rj   __name__ rk   r9   <module>rx      s     
   / 3tH~,,- .  ?@5577 
'
'D;I 
JZgT1T 1hc  S # RV  .B zF rk   