# -*- coding: utf-8 -*-
"""导出 A4 打印文件：3508x2480 @300dpi（297x210mm，1.4143:1 与源图完全同比例，不裁不拉伸）"""
import os, glob
from PIL import Image, ImageFilter

SRC = {'配色图': '/data/www/files/heibanbaoArt/color_a4',
       '线条图': '/data/www/files/heibanbaoArt/line_a4'}
OUT = '/data/www/files/heibanbaoArt/打印版'
W, H = 3508, 2480  # A4 横版 @300dpi

for tag, d in SRC.items():
    sub = os.path.join(OUT, tag)
    os.makedirs(sub, exist_ok=True)
    for f in sorted(glob.glob(os.path.join(d, '*.jpg'))):
        im = Image.open(f).convert('RGB').resize((W, H), Image.LANCZOS)
        im = im.filter(ImageFilter.UnsharpMask(1.4, 60, 3))
        p = os.path.join(sub, os.path.basename(f))
        im.save(p, quality=95, subsampling=0, dpi=(300, 300))
        print('OK', p, f'{os.path.getsize(p)/1048576:.2f}MB', im.size)
