' for i in range(1,8))+'from pathlib import Path import json, base64, html, textwrap from io import BytesIO from PIL import Image, ImageDraw, ImageFont from reportlab.pdfgen import canvas from reportlab.lib.utils import ImageReader ROOT=Path(__file__).resolve().parent BOOK=json.loads((ROOT/'book.json').read_text()) FONT='/System/Library/AssetsV2/com_apple_MobileAsset_Font7/8dc7805506cc9f233dcc19aabf593196842a47ae.asset/AssetData/Hannotate.ttc' SANS='/System/Library/Fonts/Hiragino Sans GB.ttc' W,H=1024,1696 TOP=112 SCALE=2 def f(size,hand=True): return ImageFont.truetype(FONT if hand else SANS,size*SCALE) def wrap(t,font,maxw,draw): out=[] for raw in t.split('\n'): line='' for c in raw: if line and draw.textlength(line+c,font=font)>maxw: out.append(line); line=c else: line+=c out.append(line) return out def compose(p): num=p['number'] artpath=ROOT/'art'/f'page-{num:02d}-final.png' art=Image.open(artpath).convert('RGB').resize((1024*SCALE,1536*SCALE),Image.Resampling.LANCZOS) page=Image.new('RGB',(W*SCALE,H*SCALE),'white'); page.paste(art,(0,TOP*SCALE)) d=ImageDraw.Draw(page) svg=[f'') out=ROOT/'pages'/f'page-{num:02d}.png'; page.save(out) (ROOT/'editable'/f'page-{num:02d}.svg').write_text('\n'.join(svg)) return out paths=[compose(p) for p in BOOK['pages']] pdfpath=ROOT/'output/pdf/最强模型茶话会.pdf' c=canvas.Canvas(str(pdfpath),pagesize=(512,848)) c.setTitle(BOOK['title']); c.setAuthor('Codex · Reddit讨论改编') for p in paths: encoded=BytesIO() Image.open(p).convert('RGB').save(encoded,format='JPEG',quality=96,subsampling=0) encoded.seek(0) c.drawImage(ImageReader(encoded),0,0,width=512,height=848); c.showPage() c.save() # A contact sheet for visual inspection; page images remain full resolution. sheet=Image.new('RGB',(1024,1696),'#E9E7ED') for i,p in enumerate(paths): im=Image.open(p); im.thumbnail((326,540)) x=(i%3)*342+(326-im.width)//2; y=(i//3)*564 sheet.paste(im,(x,y)) sheet.save(ROOT/'overview.jpg',quality=92) index='''
7页 · 6位虚构朋友 · 根据两帖公开讨论重新改编。评论为个人体验,非产品实测。
' for i in range(1,8))+'