import asyncio,os,json,sys from playwright.async_api import async_playwright M=json.load(open('/work/mama-box/tools/share-card/manifest.json'));I=json.load(open('/work/mama-box/tools/share-card/icons.json')) OUT='/work/mama-box/assets/share/' GEN={'calc':'', 'quiz':'', 'plaza':''} def svg(x): ic=x.get('ic') or '' if ic.startswith('test:'): p=I['TI'][ic[5:]] elif ic in GEN: p=GEN[ic] else: p=I['IC'].get(ic) or GEN['quiz'] return ''+p+'' async def main(): only=sys.argv[1:] async with async_playwright() as p: b=await p.chromium.launch(executable_path=os.environ.get('CH'),args=['--allow-file-access-from-files']) pg=await b.new_page(viewport={'width':750,'height':600}) await pg.goto('file:///work/mama-box/tools/share-card/tpl.html') n=0 for x in M: if only and x['k'] not in only and not any(x['k'].startswith(o) for o in only): continue await pg.evaluate("([x,s])=>window.draw(x,s)",[x,svg(x)]) await pg.evaluate("document.fonts.ready") fn=OUT+x['k']+'.jpg'; os.makedirs(os.path.dirname(fn),exist_ok=True) await pg.screenshot(path=fn,type='jpeg',quality=84,clip={'x':0,'y':0,'width':750,'height':600}); n+=1 print('rendered',n) await b.close() asyncio.run(main())