
    (<i>                    \   d Z ddlm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
 ddlmZmZmZ ej                  j!                  d e ee      j&                               ddlZdZeZdZd	Zd
Zedz  Zedz  Zedz  Zedz  ZdZdZg dZ dZ!dZ"dddZ#ddZ$ddZ%ddZ&e'dk(  r e&        yy)uU  Meta 캐러셀 광고 A-2 (Problem 슬라이드) v2 — 감정 사진 배경 + 오버레이 개선.

변경 사항:
1. Gemini 배경: 라인 아이콘 그래픽 → 감정적 사진 장면 (비 오는 밤 사무실)
2. SVG 아이콘 레이어 제거
3. overlay-dark opacity 완화 (0.88 → 0.62)
4. 헤드라인 좌측 정렬 유지 확인
    )annotationsN)Path)sync_playwright)WORKSPACE_ROOTFONT_DIR
CTA_MIN_PX   X   gzG?gffffff?z%output/meta-ads/a-group-v6/productionz_bg_a2_problem.jpgzmeta-A2-problem.pngz_a2_problem_template.htmlu  Cinematic photograph scene: A lone person's silhouette standing at a dark office window at night, rain streaking down the glass outside. The figure faces away from camera — backlit, solitary. On the desk behind: a dead monitor screen showing only darkness, scattered papers and documents. Color palette: cold blue-grey tones, desaturated, moody. Lighting: only faint city glow through the rain-soaked window casting blue-silver reflections. Atmosphere: profound isolation, quiet desperation, late-night exhaustion. IMPORTANT COMPOSITION: The upper 15% of the image should be dark and relatively clear/simple. The central 50% area (middle of frame) should have MINIMAL visual clutter — the silhouette figure should be positioned to one side or slightly off-center. The lower 35% should transition to deeper darkness for text readability. NO icons, NO graphics, NO illustrations, NO charts, NO infographics. NO text, NO watermarks, NO overlays. Photorealistic cinematic photography style. Film grain texture. Shallow depth of field. Aspect ratio: square 1:1, 1080x1080 pixels. Mood keywords: loneliness, stagnation, isolation, cold night, silent office.gemini-2.5-flash-image)zgemini-3.1-flash-image-previewzgemini-3-pro-image-previewr   z0https://generativelanguage.googleapis.com/v1betaz3https://www.googleapis.com/auth/generative-languagec                r   t         j                         r| st        d       	 t         j                         r&t         j                          t        dt                 t        d       t	        j
                         }t        dt        |       d       d| dd}t        gt        z   }d	}|D ]  }t         d
| d}ddt        igigdddgid}t        d| d       t        j                         }	 t        j                  |||d      }	|	j                  dv r+t        d|	j                   d|        d|	j                   }|	j                          t        j                         |z
  }
|	j!                         }|j#                  dg       }|st        dt%        |      d	d         d}|d   j#                  di       j#                  dg       }t'        d  |D        d	      }|?|D cg c]  }d|v s|j#                  dd!       }}t        d"|d	d#         d$|d	d%  }{|d&   j#                  d'd(      }t)        j*                  |d&   d)         }d*|v rd+nd,}t         j-                  |      }|j/                  |       t        d-|j0                   d.t        |      d/d0|
d1d2| d	       |c S  t7        d6|       c c}w # t        j2                  $ r(}t        d3| d4| d       t%        |      }Y d	}~Td	}~wt4        $ r(}t        d5| d4| d       t%        |      }Y d	}~d	}~ww xY w)7uX   Gemini API로 감정적 사진 배경 이미지를 생성하고 JPEG로 저장합니다.u_   [배경] 캐시된 배경 이미지 삭제 후 재생성 (force=False → 기존 파일 사용)u)   [배경] 기존 배경 이미지 삭제: u(   [배경] Gemini API 토큰 획득 중...u   [배경] 토큰 획득 완료 (z chars)zBearer zapplication/json)AuthorizationzContent-TypeNz/models/z:generateContentpartstextresponseModalitiesIMAGETEXT)contentsgenerationConfigu1   [배경] 이미지 생성 요청 중... (모델: )i,  )headersjsontimeout)i  i  u$   [배경] 모델 접근 불가 (HTTP z): zHTTP 
candidatesu2   [배경] candidates 없음, 다음 모델 시도:    u   candidates 없음r   contentc              3  *   K   | ]  }d |v s|  yw)
inlineDataN ).0ps     X/home/jay/workspace/.worktrees/task-2057-dev2/tools/ai-image-gen/gen_production_a2_v2.py	<genexpr>z&generate_background.<locals>.<genexpr>   s     EQ<13DqEs   	 u0   [배경] 이미지 데이터 없음. 텍스트:    u   이미지 데이터 없음:    r   mimeTypez
image/jpegdatajpegz.jpgz.pngu   [배경] 완료:  (,z bytes, z.1fu   초) (모델: u   [배경] HTTP 오류: u
    (모델: u   [배경] 오류: u6   모든 Gemini 모델 시도 실패. 마지막 오류: )BG_JPEGexistsprintunlinkgcloud_authget_access_tokenlenMODEL_IDFALLBACK_MODEL_IDSGEMINI_API_BASE	BG_PROMPTtimerequestspoststatus_coderaise_for_statusr   getstrnextbase64	b64decodewith_suffixwrite_bytesname	HTTPError	ExceptionRuntimeError)forcetokenr   models_to_try
last_errormodelurlpayloadstartrespelapsedr'   r   r   
image_partr    textsmimeimage_bytesext	save_pathes                         r!   generate_backgroundrW   L   si   ~~oq ~~9'CD	
45((*E	+CJ<w
?@ #5'**G J!33MJ 2 !%0@A!VY$7#89:!57H I
 	A%JK		)	==gGSQD:-<T=M=M<NcRWQXYZ$T%5%5$67
!!#iikE)G99;D,3JJ3t9UYVY?J[\]0
qM%%i488"EEE%EtLJ!49IqVq[vr*IIHrPQTU;E"1I;G
l+//
LID **:l+CF+KLK"dN&C++C0I!!+.%inn%5RK8H7K8T[\_S``notnuuvwxS2h OPZ|\
]]/ J !! 	*1#Zwa@AQJ 	%aS
5';<QJ	sQ   5AKA'K0>K.	K8KK)BKKL6LL6L11L6c                    dt          dt          dt          dt          dt          d|  dt         dt         d	t         d
t         dt         dt         dt
         dS )u  A-2 Problem 슬라이드 HTML 오버레이 v2를 빌드합니다.

    변경사항:
    - .top-icons 섹션 및 SVG 아이콘 3개 완전 제거
    - .overlay-dark 상단 opacity 0.88 → 0.62 (배경 사진 투과)
    - 헤드라인 좌측 정렬 (left: 64px) 유지
    z<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
  @font-face {
    font-family: 'Pretendard';
    src: url('file://z/Pretendard-Black.otf') format('opentype');
    font-weight: 900;
  }
  @font-face {
    font-family: 'Pretendard';
    src: url('file://z/Pretendard-ExtraBold.otf') format('opentype');
    font-weight: 800;
  }
  @font-face {
    font-family: 'Pretendard';
    src: url('file://z/Pretendard-Bold.otf') format('opentype');
    font-weight: 700;
  }
  @font-face {
    font-family: 'Pretendard';
    src: url('file://z/Pretendard-Medium.otf') format('opentype');
    font-weight: 500;
  }
  @font-face {
    font-family: 'Pretendard';
    src: url('file://u  /Pretendard-Regular.otf') format('opentype');
    font-weight: 400;
  }

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

  body {
    width: 1080px;
    height: 1080px;
    overflow: hidden;
    background: #1A202C;
  }

  .canvas {
    width: 1080px;
    height: 1080px;
    position: relative;
    font-family: 'Pretendard', 'Noto Sans KR', sans-serif;
    overflow: hidden;
  }

  /* ─── 배경 이미지 ─── */
  .bg {
    position: absolute;
    inset: 0;
    background: url('file://uy  ') center center / cover no-repeat;
  }

  /* ─── 전체 어둠 오버레이 — 배경 사진이 보이도록 opacity 완화 ─── */
  /* 변경: 상단 0.88 → 0.62 (배경 감정 전달을 위해) */
  .overlay-dark {
    position: absolute;
    inset: 0;
    background: linear-gradient(
      to bottom,
      rgba(15, 18, 28, 0.62) 0%,
      rgba(15, 18, 28, 0.45) 20%,
      rgba(15, 18, 28, 0.38) 45%,
      rgba(10, 12, 20, 0.65) 72%,
      rgba(6, 8, 14, 0.95) 100%
    );
  }

  /* ─── 헤드라인 영역 (Center 50%) — LEFT 정렬, 단호한 선언 느낌 ─── */
  /* Top 15% ~ 65%: y=162 ~ y=702 */
  .headline-wrap {
    position: absolute;
    top: 162px;
    left: 64px;
    right: 64px;
    height: 540px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: flex-start;
  }

  .headline {
    font-size: z?px;
    font-weight: 900;
    color: #F7F8FA;
    line-height: u  ;
    letter-spacing: -3.5px;
    word-break: keep-all;
    text-align: left;
    text-shadow: 0 2px 28px rgba(0,0,0,0.75);
  }

  /* "방법이 없었던 거다." — 딥 앰버 포인트 컬러 강조 */
  .headline .accent {
    color: #D97706;
    text-shadow:
      0 0 40px rgba(217, 119, 6, 0.45),
      0 2px 24px rgba(0,0,0,0.65);
    font-weight: 900;
  }

  /* ─── 하단 서브카피 영역 (Bottom 35%) ─── */
  /* y=702 ~ y=1080 */
  .bottom-zone {
    position: absolute;
    top: 702px;
    left: 0;
    right: 0;
    bottom: 0;
  }

  /* 하단 어둠 강화 — 텍스트 가독성 보강 (유지) */
  .bottom-gradient {
    position: absolute;
    inset: 0;
    background: linear-gradient(
      to bottom,
      rgba(6, 8, 14, 0.0) 0%,
      rgba(6, 8, 14, 0.75) 35%,
      rgba(6, 8, 14, 0.95) 100%
    );
  }

  .subcopy-wrap {
    position: absolute;
    bottom: 80px;
    left: 64px;
    right: 72px;
  }

  /* 1번 서브카피 문장 */
  .subcopy-line1 {
    font-size: zQpx;
    font-weight: 400;
    color: rgba(200, 205, 216, 0.80);
    line-height: u   ;
    letter-spacing: -0.8px;
    word-break: keep-all;
    margin-bottom: 20px;
    text-align: left;
  }

  /* 2번 서브카피 문장 — 여운을 위한 분리 */
  .subcopy-line2 {
    font-size: zQpx;
    font-weight: 500;
    color: rgba(218, 220, 230, 0.88);
    line-height: u   ;
    letter-spacing: -0.8px;
    word-break: keep-all;
    text-align: left;
  }

  /* 페이지 인디케이터 2/5 */
  .page-indicator {
    position: absolute;
    bottom: 32px;
    right: 52px;
    font-size: u  px;
    font-weight: 500;
    color: rgba(180, 185, 200, 0.45);
    letter-spacing: 2px;
  }

</style>
</head>
<body>
<div class="canvas">

  <!-- 배경 이미지 (감정적 사진 장면) -->
  <div class="bg"></div>

  <!-- 전체 어둠 오버레이 (opacity 완화 — 배경 사진 감정 전달) -->
  <div class="overlay-dark"></div>

  <!-- 상단 15%: 미니멀 여백 (아이콘 없이 깨끗하게) -->
  <!-- SVG 아이콘 3개 완전 제거 → 배경 사진이 시각적 역할 대체 -->

  <!-- 헤드라인 (Center 50%) — LEFT 정렬, 좌측 여백 64px, 단호한 선언 -->
  <div class="headline-wrap">
    <div class="headline">
      문제는 노력이 아니다.<br>
      <span class="accent">방법이 없었던 거다.</span>
    </div>
  </div>

  <!-- 하단 서브카피 영역 -->
  <div class="bottom-zone">
    <div class="bottom-gradient"></div>
    <div class="subcopy-wrap">
      <p class="subcopy-line1">지인 명단은 바닥났고, 알려줄 멘토도 없었다.</p>
      <p class="subcopy-line2">혼자 버티는 건 미덕이 아니라 손실이다.</p>
    </div>
  </div>

  <!-- 페이지 인디케이터 -->
  <div class="page-indicator">2 / 5</div>

</div>
</body>
</html>)r   
_SIZE_88PX_LH_1_18_CTA_PX_LH_1_65
_SIZE_26PXbg_paths    r!   
build_htmlr`      s     Z  
 Z  
 Z  
 Z  
 Z  : %I !&B |   /^ y   	 y    | *KO O    c                   t        t        | j                                     }t        j	                  |d       t        dt                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       |j!                          	 ddd       t        j#                         j$                  }t        dt         d|dd       y# |j!                          w xY w# 1 sw Y   TxY w)uN   HTML 오버레이를 Playwright로 캡처하여 최종 PNG를 저장합니다.zutf-8)encodingu&   [오버레이] HTML 템플릿 저장: u*   [오버레이] Playwright 캡처 시작...i8  )widthheight)viewportzfile://networkidle)
wait_untili	  Tparentsexist_okpng)pathtypeNu   [오버레이] 완료: r)   r*   z bytes))r`   r<   resolve	HTML_TEMP
write_textr-   r   chromiumlaunchnew_pagegotowait_for_timeout
OUTPUT_PNGparentmkdir
screenshotclosestatst_size)r_   html_contentr    browserpagesizes         r!   capture_overlayr     s0   c'//"345L8	29+
>?	
67		 
a**##%	##tt-L#MDII	 1 1 345-IP!!$'##D4#@OOZuO=MMO
 ??$$D	#J<r$q
AB MMO
 
s%   !E0=BEE0E--E00E9c                 ,   t        d       t        d       t        d       t        dt                t        d       t        j                  dd       t	        d      } t        |        t        d       t        d	t                t        d       y )
Nz<============================================================u5   Meta 캐러셀 A-2 Problem v2 이미지 생성 시작u@   변경: 감정 사진 배경 + 아이콘 제거 + overlay 완화u   출력: Tri   )rF   z=
============================================================u   완료: )r-   rw   
OUTPUT_DIRry   rW   r   r^   s    r!   mainr     sx    	(O	
AB	
LM	HZL
!"	(OTD1 "-G G	/	HZL
!"	(Ora   __main__)F)rF   boolreturnr   )r_   r<   r   r<   )r_   r   r   None)r   r   )(__doc__
__future__r   r>   sysr6   pathlibr   r7   playwright.sync_apir   
gen_configr   r   r   rm   insertr<   __file__rx   r/   r]   r[   rY   rZ   r\   r   r+   rw   rp   r5   r2   r3   r4   GEMINI_SCOPErW   r`   r   r   __name__r   ra   r!   <module>r      s    #  
    / ; ; 3tH~,,- . 


 EE

+
+//
44	S 
. $ 
 EDM^lW~C8( zF ra   