Publish cache-safe Russian text on site photographs, agent=codex
This commit is contained in:
+3
-5
@@ -1,19 +1,17 @@
|
||||
"""Preserve generated editorial photographs and export responsive WebP versions."""
|
||||
from pathlib import Path
|
||||
from PIL import Image, ImageDraw, ImageOps
|
||||
import json, shutil
|
||||
import json
|
||||
ROOT=Path(__file__).resolve().parent
|
||||
manifest=json.loads((ROOT/'content/photo-manifest.json').read_text(encoding='utf-8'))
|
||||
originals=ROOT/'artwork/photos-selected'; originals.mkdir(parents=True,exist_ok=True)
|
||||
tiles=[]
|
||||
for item in manifest:
|
||||
slug=item['slug']; source=ROOT/item['path']
|
||||
dest=originals/(slug+'.png')
|
||||
if source.resolve()!=dest.resolve():shutil.copy2(source,dest)
|
||||
slug=item['slug']; source=ROOT/item['path']; asset=item.get('asset','photo-'+slug)
|
||||
picture=Image.open(source).convert('RGB')
|
||||
picture=ImageOps.fit(picture,(1536,1024),method=Image.Resampling.LANCZOS,centering=(.5,.5))
|
||||
for width in (480,960,1536):
|
||||
picture.resize((width,round(width*2/3)),Image.Resampling.LANCZOS).save(ROOT/'assets'/f'photo-{slug}-{width}.webp',quality=83,method=6)
|
||||
picture.resize((width,round(width*2/3)),Image.Resampling.LANCZOS).save(ROOT/'assets'/f'{asset}-{width}.webp',quality=83,method=6)
|
||||
tile=Image.new('RGB',(384,280),'#05070f')
|
||||
tile.paste(picture.resize((384,256)),(0,0))
|
||||
ImageDraw.Draw(tile).text((12,263),slug,fill='#67e8f9')
|
||||
|
||||
Reference in New Issue
Block a user