# -*- coding: utf-8 -*-
"""输出符合活动要求的报送版（jpg 2~10Mb，300dpi 元数据）"""
import os
from PIL import Image, ImageFilter
SRC = '/data/www/files/pandaReadArt/best2/color'
LINE = '/data/www/files/pandaReadArt/best2/lineart'
OUT = '/data/www/files/pandaReadArt/best2/报送版'
os.makedirs(OUT, exist_ok=True)

jobs = [('2_一盏灯一百零五年', '作品二_一盏灯一百零五年_配色图', SRC),
        ('2_一盏灯一百零五年', '作品二_一盏灯一百零五年_线条图', LINE)]

for key, name, src in jobs:
    im = Image.open(os.path.join(src, f'{key}.jpg')).convert('RGB')
    w, h = im.size
    # 放大到 4:3 的 3500x2625（约300dpi下 29.6x22.2cm，接近4开）
    big = im.resize((4000, 3000), Image.LANCZOS)
    big = big.filter(ImageFilter.UnsharpMask(radius=1.6, percent=70, threshold=3))
    p = os.path.join(OUT, f'{name}.jpg')
    big.save(p, quality=97, subsampling=0, dpi=(300, 300), optimize=False)
    mb = os.path.getsize(p) / 1024 / 1024
    print(f'{name}  {big.size}  {mb:.2f}MB  {"OK(2~10MB)" if 2 <= mb <= 10 else "!! 需调整"}')
