A folder of PSDs
The studio has a reference set of album and Instagram designs as Photoshop files: 375 album spreads, a set of bridal portrait spreads, and an Instagram kit of posts and stories. They're beautiful, and they're the wrong shape for a website. A PSD is one fixed picture with layers. A customer designing their own album needs something that can take their photos, at any album size, in any order, and still look designed.
So we didn't convert the PSDs. We read them like a designer would, wrote down the rules they follow, and rebuilt those rules as code that generates templates. This post is about that generator and the decisions inside it.
Templates are built, not drawn
Everything lives in brand/album-templates/:
layouts.mjs: the photo layouts, as geometry in inches on a 36 x 12 inch spread (two 18 x 12 pages with the gutter at x = 18).ornaments.mjs: SVG pieces such as paper grain, frames, toran, kolam and garlands.directions/*.mjs: one file per design (Ivory Heirloom, Kumkum Temple, Marigold Haldi, Noir Reception, Botanical Blush, Editorial White): its palette, fonts, chapter titles and wording, frame style and special pages.build.mjs: combines a direction with the layouts and writes the output.
A layout is just rectangles:
const M = 0.75; // page margin
const G = 0.25; // gap between photos
"bleed-pair": {
label: "Two full-bleed pages",
build: () => finish({ slots: [
slot(0, 0, 18, 12, "rect", "hero", { bleed: true }),
slot(18, 0, 18, 12, "rect", "hero", { bleed: true }),
], frames: [] }),
},Each slot records whether it's portrait, landscape or square (worked out from its own width and height), and a focus point: where faces usually are. Portrait slots focus a bit above the middle (0.38 of the height), because that's where heads sit in a portrait photo.
Inches, not pixels, because the end product is printed. The same numbers place a photo in the browser preview and in the print file.
What the build writes
For each design, build.mjs renders every spread's background (paper, frames, ornaments, the parts that never change) with a headless Chromium, and writes:
template.json: the spreads, their layout options, the slots and the text positions.bg/*.webp: lightweight backgrounds for the website.print/<code>/<hash>.svg: vector masters of the same backgrounds for printing at any resolution.
The browser editor (SpreadView) draws the WebP background and puts the customer's photos into the slots on top. The print kit uses the SVG masters with the same slot geometry. Two renderers, one source of truth.
Every template has 101 spreads for a 50-sheet album: cover, opening, eight chapter openers, 90 content spreads and a closing page. Smaller albums don't get different templates; the editor picks an even spread of content spreads to keep:
const want = Math.min(total, sheets * 2 + 1);
const fixed = t.spreads.filter((s) => s.kind !== "content").map((s) => s.index);
const content = t.spreads.filter((s) => s.kind === "content").map((s) => s.index);
const keepContent = Math.max(0, want - fixed.length);
for (let k = 0; k < keepContent; k++) {
picked.add(content[Math.floor(((k + 0.5) * content.length) / keepContent)]);
}The (k + 0.5) picks from the middle of each equal slice, so a 30-sheet album keeps the rhythm of the full design (chapter, a few content spreads, chapter) instead of losing its whole second half.
Rectangles only
The first version had arches, temple-style mihrab frames, ovals, circles and rounded corners. They looked lovely in mock-ups. With real photos they had a problem: a photographer frames a shot for a rectangle. An arch crops off the top corners, which is often where the hands, the garland or the temple tower are. An oval loses even more.
The reference PSDs, it turned out, almost never do this. They get their richness from the grid: a full-bleed page facing a stack of two, three columns facing a captioned banner, overlapping frames, stepped squares. So the studio decided every photo frame would be a rectangle, and the build enforces it:
const odd = slots.find((s) => s.shape !== "rect");
if (odd) throw new Error(`${dir.code} ${layout}: photo slot ${odd.id} is "${odd.shape}" - album photos are rectangles only`);A rule in a design document gets forgotten. A rule in the build can't be. Decorative arches are still allowed in the backgrounds; it's only photos that must be rectangles.
Reading 375 spreads
The content layouts came from going through the whole reference set and noting each distinct photo grid. The first pass added layouts like portrait plus a stacked pair facing a bleed page, and three columns facing a captioned banner. A second pass, across all 375 spreads, added eight more: a bleed photo with a column of three facing a framed landscape, staggered landscape pairs, a big framed portrait offset against a smaller landscape, and others.
Reviewing that many layouts by eye needs help, so the build has a QA mode that renders one sample spread per layout to a folder of JPEGs:
node brand/album-templates/build.mjs --qa=/tmp/qa --qa-allChanging a layout is a migration
Here's the trap with generated templates. A customer's album doesn't store pictures of spreads; it stores which layout each spread uses and which photo is in each slot. If you change the geometry of an existing layout, every album already in progress silently moves its photos.
So the rule, written in the README, is: don't edit a layout's geometry. Add a new layout instead, or bump the template's version and check the existing albums. Layouts are like database columns: once someone's data depends on them, changing them is a migration, not a tweak.
Portrait albums and a second shape
Portrait sessions wanted something different: one hero photo, a framed inset, an oversized title word, cinematic tones. Six portrait designs were added, each in two shapes: the 12 x 36 inch landscape spread and a vertical album with 12 x 15 inch pages (a 24 x 15 spread). That second shape meant the spread size couldn't be hard-coded any more, so the editor, SpreadView and the autofill now read it from template.json. Portrait albums also come in smaller sizes (10, 15, 20 or 30 sheets), listed per template.
The same kit for Instagram
The Instagram templates reuse the same ornaments and the same six design directions, so a couple's album and their Instagram post look like one family. They're authored in "units" where one unit is 100 pixels, so a 4:5 post is 10.8 x 13.5 units, a square post 10.8 x 10.8 and a story 10.8 x 19.2. The build exports them in pixels. They follow the studio's Instagram PSDs (title over a photo, a name band between two photos, polaroid mats, "Now booking" promos) and, like the albums, every photo frame is a rectangle.
Takeaways
- Don't convert design files; extract the rules and generate. A generator can make 101 spreads in six styles; a folder of PSDs can't adapt to anyone's photos.
- Work in the units of the final product. Inches for print meant the preview and the print file agree.
- Put design decisions in the build. "Rectangles only" is a thrown error, not a guideline.
- When saved data refers to a definition, the definition is a schema. Add new layouts; don't move old ones.
- Build review tools for generated output. One QA spread per layout made 375 spreads reviewable.