공공기관2 작업 중. _temp 몽타주(재생성가능)는 제외. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
43 lines
1.9 KiB
Python
43 lines
1.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""57+ 어문(이미지없음) 행만 몽타주 — 이미지 있는 행 시각식별용."""
|
|
import os, glob
|
|
import openpyxl
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
DIR = os.path.dirname(__file__)
|
|
SHOT = os.path.join(DIR, '_nshots2')
|
|
t = glob.glob(os.path.join(DIR, '*.xlsx'))
|
|
t = [p for p in t if 'backup' not in p and not os.path.basename(p).startswith(('~$', '_'))][0]
|
|
ws = openpyxl.load_workbook(t).active
|
|
rows = [r for r in range(57, ws.max_row + 1)
|
|
if ws.cell(r, 12).value in ('페이지', '게시판') and '이미지' not in str(ws.cell(r, 14).value or '')
|
|
and os.path.exists(os.path.join(SHOT, f'r{r}.png'))]
|
|
lab = {r: (ws.cell(r, 7).value or ws.cell(r, 6).value or ws.cell(r, 5).value or '') for r in rows}
|
|
Lof = {r: ws.cell(r, 12).value for r in rows}
|
|
CW, CH = 268, 470
|
|
COLS, ROWS = 4, 4
|
|
PER = COLS * ROWS
|
|
try:
|
|
fnt = ImageFont.truetype('C:/Windows/Fonts/malgun.ttf', 19)
|
|
except Exception:
|
|
fnt = ImageFont.load_default()
|
|
cells = []
|
|
for r in rows:
|
|
im = Image.open(os.path.join(SHOT, f'r{r}.png')).convert('RGB')
|
|
if im.height > 780:
|
|
im = im.crop((0, 0, im.width, 780))
|
|
im.thumbnail((CW, CH))
|
|
cells.append((r, im))
|
|
for k in range((len(cells) + PER - 1) // PER):
|
|
sub = cells[k * PER:(k + 1) * PER]
|
|
cw, ch = CW + 12, CH + 32
|
|
M = Image.new('RGB', (COLS * cw, ROWS * ch), (255, 255, 255))
|
|
d = ImageDraw.Draw(M)
|
|
for i, (r, im) in enumerate(sub):
|
|
cx = (i % COLS) * cw
|
|
cy = (i // COLS) * ch
|
|
d.text((cx + 4, cy + 3), f"r{r}[{'B' if Lof[r]=='게시판' else 'P'}] {str(lab[r])[:13]}", fill=(200, 0, 0), font=fnt)
|
|
M.paste(im, (cx + 6, cy + 28))
|
|
d.rectangle([cx + 2, cy + 26, cx + cw - 4, cy + ch - 4], outline=(150, 150, 150))
|
|
M.save(os.path.join(DIR, f'_nb{k+1:02d}.png'))
|
|
print('grids', (len(cells) + PER - 1) // PER, 'cells', len(cells), 'rows', rows[0], '~', rows[-1])
|