
    Wi)                         d Z ddlZddlZddl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
 ej                  j                  dd        e
d      Z e
d      ZdZdZd	 Zd
edefdZdedefdZd Zedk(  r e        yy)u   인카다이렉트 M1-3 영업지원 배너 1200x628 생성 스크립트
hybrid-image 파이프라인: Gemini 배경 + HTML/CSS 오버레이 (Playwright)
    N)Pathz&/home/jay/workspace/tools/ai-image-genzH/home/jay/workspace/output/google-ads/banners/incar-support-1200x628.pngz"/tmp/incar_support_bg_1200x628.jpgu  Bright, clean coworking space interior. One person's side profile working on a laptop at a personal desk with two monitors, face not visible. A single coffee cup on the desk. Desktop screen slightly blurred. Warm natural sunlight streaming through large windows. Comfortable, well-organized morning work atmosphere. Soft warm tones — cream, warm white, light wood. Inviting, approachable, professional but not cold. No money, no rockets, no complex tech equipment, no icons or illustrations. Photo-realistic quality, wide horizontal crop.u  <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
  @import url('https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@400;500;700;900&display=swap');
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body { width: 1200px; height: 628px; overflow: hidden; font-family: 'Pretendard', 'Noto Sans KR', sans-serif; }
  .container {
    position: relative;
    width: 1200px;
    height: 628px;
    background-color: #f5f6f8;
  }
  .bg-image {
    position: absolute;
    top: 0; left: 0;
    width: 100%; height: 100%;
    background-image: var(--bg-url);
    background-size: cover;
    background-position: center right;
  }
  /* 좌측 화이트→투명 그라데이션 오버레이 (텍스트 가독성) */
  .gradient-overlay {
    position: absolute;
    top: 0; left: 0;
    width: 75%;
    height: 100%;
    background: linear-gradient(
      to right,
      rgba(248, 249, 252, 1.0) 0%,
      rgba(248, 249, 252, 0.97) 40%,
      rgba(248, 249, 252, 0.85) 60%,
      rgba(248, 249, 252, 0.5) 80%,
      rgba(248, 249, 252, 0.0) 100%
    );
  }
  /* 텍스트 영역 (좌측 60%) */
  .text-area {
    position: absolute;
    top: 0; left: 0;
    width: 680px;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 50px 60px;
    gap: 22px;
  }
  /* 브랜드 뱃지 */
  .brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: rgba(43, 87, 151, 0.10);
    border: 1.5px solid rgba(43, 87, 151, 0.30);
    border-radius: 6px;
    padding: 7px 16px;
    width: fit-content;
  }
  .brand-badge-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #2B5797;
  }
  .brand-badge-text {
    font-size: 32px;
    font-weight: 600;
    color: #2B5797;
    letter-spacing: -0.02em;
    line-height: 1.2;
  }
  /* 헤드라인 */
  .headline {
    font-size: 50px;
    font-weight: 800;
    color: #1B365D;
    line-height: 1.25;
    letter-spacing: -0.03em;
    word-break: keep-all;
  }
  /* 서브카피 구분선 */
  .divider {
    width: 48px;
    height: 3px;
    background: #C5A572;
    border-radius: 2px;
    margin: 2px 0;
  }
  /* 서브카피 — 지원 항목 */
  .subcopy {
    font-size: 32px;
    font-weight: 500;
    color: #2B5797;
    letter-spacing: -0.02em;
    line-height: 1.4;
  }
  .subcopy .pipe {
    color: #C5A572;
    font-weight: 600;
    margin: 0 6px;
  }
  .subcopy .accent {
    color: #C5A572;
    font-weight: 700;
  }
  /* CTA 버튼 */
  .cta-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #2B5797;
    color: #FFFFFF;
    font-size: 34px;
    font-weight: 700;
    padding: 16px 42px;
    border-radius: 8px;
    width: fit-content;
    letter-spacing: -0.01em;
    margin-top: 6px;
  }
</style>
</head>
<body>
<div class="container">
  <div class="bg-image"></div>
  <div class="gradient-overlay"></div>
  <div class="text-area">
    <div class="brand-badge">
      <div class="brand-badge-dot"></div>
      <span class="brand-badge-text">인카금융서비스</span>
    </div>
    <div class="headline">무자본창업,<br>인카가 도와드립니다</div>
    <div class="divider"></div>
    <div class="subcopy">
      DB 자동화<span class="pipe">|</span>AI 무상 세팅<span class="pipe">|</span>정착금 <span class="accent">최대 1,000만원</span>
    </div>
    <div class="cta-button">무료 상담 신청</div>
  </div>
</div>
</body>
</html>c                  *    dd l } | j                         S )Nr   )gcloud_authget_access_token)r   s    K/home/jay/workspace/output/google-ads/banners/gen_incar_support_1200x628.py	get_tokenr      s    ''))    tokenreturnc                    dd l }g d}d}|D ])  }t        d|        | d| d}d|  dd	}d
dt        igigdddgid}	 |j                  |||d      }|j                  dv rt        d| d|j                   d       v|j                          |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 , d }d }t        j                  j!                  |      rBt#        |      j%                         }t'        j(                  d!|      }|r|j+                  d"      }|scd#}t        j                  j!                  |      rBt#        |      j%                         }t'        j(                  d!|      }|r|j+                  d"      }|rPdd l }d$D ]F  }t        d%|        d&| d'| }d(di}d
dt        igigdddgid}	 |j                  |||d      }|j                  dv r>i }	 |j                         }t        d| d|j                   d)t-        |      d d*         |j                          |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 I t        d+       y,# t        $ r}t        d| d|        Y d }~vd }~ww xY w# t        $ r Y "w xY w# t        $ r}t        d| d|        Y d }~d }~ww xY w)-Nr   )gemini-3.1-flash-image-previewgemini-3-flash-previewzgemini-3-pro-image-previewz0https://generativelanguage.googleapis.com/v1betau$     [BG] Gemini 배경 생성 시도: z/models/z:generateContentzBearer zapplication/json)AuthorizationContent-TypepartstextresponseModalitiesIMAGETEXT)contentsgenerationConfigx   )headersjsontimeout)i  i  i  z  [BG] u	    실패 (u   ), 다음 시도...
candidatescontent
inlineDatadatau      [BG] 배경 이미지 저장:  (,z bytes)Tu	    오류: z/home/jay/workspace/.env.keysz2GEMINI_API_KEY\s*=\s*["\']?([A-Za-z0-9_\-]+)["\']?   z/home/jay/workspace/.env)r   r   u     [BG] API key 방식 시도: z8https://generativelanguage.googleapis.com/v1beta/models/z:generateContent?key=r   z):    uD     [BG] Gemini 배경 생성 실패 — 그라데이션 폴백 사용F)requestsprintGEMINI_BG_PROMPTpoststatus_coderaise_for_statusr   getbase64	b64decodeBG_TEMP_PATHwrite_byteslen	Exceptionospathexistsopenreadresearchgroupstr)r
   r$   	model_idsgemini_api_basemodel_idurlr   payloadrespr   r   part	img_byteseapi_key_fileapi_keyr   menv_patherr_datas                       r   generate_bg_imagerH      s   jIHO 4XJ?@ !(3CD&-eW$5GYZ!V-=$>#?@A!57H I
	==gGS=QD?2z43C3C2DDWXY!!#99;DHH\B40377	2FJJ7TVWE  4' & 0 0l1CF1K LI ,,Y7<\N"SQZ^\]L^^efg !6 3LG	ww~~l#|$))+IIKWUggajG-77>>(#8n))+G		OQXYA''!*T 	H28*=>LXJVklsktuC%'9:G%1A(B'CDE%9GV;L$MG}}S'QT}U##6!H#'99; GH:Yt7G7G6HCPXMZ^[^L_K`ab%%'yy{t4Q7;;IrJNNwXZ[! $D#t+$*$4$4T,5G5O$P	$00; @bQTU^Q_`aPbbijk#$+	> 

PQm  	GH:Yqc23	H %   z1#67s|   ?M#AM##AM#6M#?%N%N5*N AN ANN#	N,NN	NNNN	O $N;;O bg_availablec                 N   ddl m} t        }| r4t        j	                         r dt         }|j                  dd| d      }n|j                  dd      }t        j                  dd	d
d      5 }|j                  |       |j                  }d d d        	  |       5 }|j                  j                         }|j                  ddd      }|j                  d d       |j                  d       t        j                   j#                  dd       |j%                  t'        t              d       |j)                          d d d        t+        dt                	 t-        j.                         y# 1 sw Y   xY w# 1 sw Y   >xY w# t-        j.                         w xY w)Nr   )sync_playwrightzfile://z background-image: var(--bg-url);zbackground-image: url('z');zKbackground: linear-gradient(135deg, #EBF2FF 0%, #D6E8FF 50%, #C5D9F5 100%);z.htmlwzutf-8F)suffixmodeencodingdeletei  it  )widthheight)viewportnetworkidle)
wait_untili  T)parentsexist_okpng)r2   typeu     [캡처] )playwright.sync_apirK   HTML_TEMPLATEr-   r3   replacetempfileNamedTemporaryFilewritenamechromiumlaunchnew_pagegotowait_for_timeoutOUTPUT_PATHparentmkdir
screenshotr9   closer%   r1   unlink)	rI   rK   htmlbg_uriftmp_htmlpbrowserpages	            r   render_with_playwrightrs      ss   3D++-<.)||>5fXSAC ||>ik 
	$	$G#X]	^ bc	66 	!jj'')G##ts-K#LDIIz*}IE!!$'$$TD$AOO[!1O>MMO	 	K=)*
		(! 
	 	 			(s1   .E5F B(FF 5E>F
F F$c            	         t        d       t        j                         } 	 t               }t        |      }t        |      }t        j                         | z
  }|rft        j                         rRt        j                         j                  dz  }t        dt         d|dd	|d
d       t        j                  d       y t        d       t        j                  d       y # t        $ r}t        d| d       d}Y d }~d }~ww xY w)NuC   === 인카다이렉트 M1-3 영업지원 배너 1200x628 생성 ===u!     [인증] 토큰 획득 실패: u    — 폴백 배경 사용Fi   u   === 완료: r    z.0fz KB, z.1fu   초) ===r   u   === 실패 ===r"   )r%   timer   rH   r0   rs   rf   r3   statst_sizesysexit)startr
   bg_okrB   okelapsedsize_kbs          r   mainr      s    	
OPIIKE!%( 
 	&BiikE!G	k  """$,,t3[MGC=gc](ST  1!4MNOs   C! !	D*D  D__main__)__doc__rx   r1   r+   ru   r   r6   
subprocessr]   pathlibr   r2   insertrf   r-   r&   r[   r   r9   boolrH   rs   r   __name__ r	   r   <module>r      s     	    	    ; <]^89 v M`*
QS QT Qh $ @2 zF r	   