Cotton code
83 lines · 3.8 KB · PythonRaw
#!/usr/bin/env python3"""Put the Photos tool's painted materials into the Loom package's catalogue.    python3 scripts/import-photos-materials.py [<layers directory>]The layers were painted with Codex (30 Oct 2026, after the lab print and thealbum board the owner chose) and cut out of the paintings (keyed off green, theinstant print's window keyed off magenta and cut through, the bookcloth madeseamless at the chosen pictures' own oxblood, #421512, a little redder thanthe #3B1F22 their brief named); the directory holds them as the faces laythem (CottonFaces' `Cotton/PhotoPrintFace.swift` and`Cotton/AlbumBoardFace.swift`, the cloth by `FaceGroundSurface`). No word,number or photograph is on any of them: the faces draw every picture, thedate burned into a print and the album's label live.    photos-bookcloth     the oxblood bookcloth, a seamless tile (JPEG)    photo-print-shadow   a print's shadow on the cloth, a nine-slice made                         from a square's silhouette (its corners kept, its                         middle stretched to any print), the curled lower                         right corner's shadow in it    photo-print-sheen    the glossy print's sheen, a smooth soft gradient                         stretched over the whole print, picture and border    album-board          the empty cork board in its pine frame (JPEG)    album-board-shadow   its shadow on the cloth, larger than the board    album-instant        a blank instant print, its square window cut                         through, its shadow round it    album-pin            a brass drawing pin's head, its shadow round it    album-label          a blank cream paper label, its shadow round itA lab print's border is no picture: it is a shape the face draws over thephotograph, so no painted layer ever covers a picture. Each is at least 3xthe most it is drawn at on a phone (a shadow, a blur, less), declared 3x (2xon the Mac) as the card paper is; the face sets the frame it draws each at.The geometry the faces lay them by (the instant print's window, the pin'shead, the label's paper, the shadows' reach), measured off the cut, is thefaces' knobs: a repainted layer owes new ones."""import jsonimport pathlibimport sysHERE = pathlib.Path(__file__).resolve().parentCATALOGUE = HERE.parent / 'apps/loom/Sources/CottonPaper/Media.xcassets'NAMES = [    'photos-bookcloth', 'photo-print-shadow', 'photo-print-sheen', 'album-board', 'album-board-shadow',    'album-instant', 'album-pin', 'album-label',]def imageset(name, extension):    folder = CATALOGUE / f'{name}.imageset'    folder.mkdir(exist_ok=True)    for old in folder.iterdir():        old.unlink()    contents = {        'images': [            {'filename': f'{name}.{extension}', 'idiom': 'universal', 'scale': '3x'},            {'filename': f'{name}.{extension}', 'idiom': 'mac', 'scale': '2x'},        ],        'info': {'author': 'xcode', 'version': 1},        'properties': {'preserves-vector-representation': False},    }    (folder / 'Contents.json').write_text(json.dumps(contents, indent=2) + '\n')    return folder / f'{name}.{extension}'def main(source):    source = pathlib.Path(source)    total = 0    for name in NAMES:        found = [source / f'{name}.{extension}' for extension in ('png', 'jpg') if (source / f'{name}.{extension}').exists()]        if len(found) != 1:            sys.exit(f'{source} holds {len(found)} pictures named {name}, not one')        picture = found[0]        target = imageset(name, picture.suffix[1:])        target.write_bytes(picture.read_bytes())        total += picture.stat().st_size        print(f'{picture.name} -> {name}')    print(f'{total // 1024} KB in all')if __name__ == '__main__':    main(sys.argv[1] if len(sys.argv) > 1 else str(pathlib.Path.home() / 'lane-briefs/photo-faces/layers'))