跳到主要内容
食谱编号68

排版食谱 · 第7章 · 图与图片

满版出血图版的摄影随笔

图版是由一个列表生成的标题样式,每张铺满整页直到成品边缘;暴风雨一图分成两半,跨过一个跨页的中缝。

本页内容
类型
摄影集
输出
Canvas
难度
中级
Postext
已用Postext 1.65.0测试
需要≥ 1.42.1
许可证
更新于2026年10月10日
代码MIT · 文本CC BY 4.0

第4–5页,共9页

  • 西班牙文样例:尚无中文版本
  • 成品尺寸280 × 210 mm
  • 1栏
  • Andada Pro 10.5/15
  • Syne
  • Syne Mono
  • 9页
  • 难度
  • Postext 1.57.1
  • 排版用时49 ms
  • 177行代码

简单来说

一本风景摄影集,用六幅照片记录山中的一天。示例演示怎样让照片铺满整页直到纸边,并让一幅照片横跨左右相对的两页。

成品一览

Sierra,一本页面为280 × 210 mm的风景摄影集:用六张图版记录花岗岩山脉中的一天,从第一缕晨光到初雪后的早晨。每张图版铺满整页直到成品边缘,只在左下角带一个小号罗马数字和时刻;第一张还带有标题SIERRA,用72 pt的Syne从黎明的天空中反白出来。暴风雨作为一整幅图跨过第4页和第5页之间的中缝。三篇短文排在靠近订口的一个100 mm宽的栏里,与其后的图版相对。暴风雨那篇短文以一张较小的黄昏图版收尾,它浮动在文字下方,罗马数字写在题注里。最后一张图版从同一块巨石上拍摄第二张图版里的冰斗,只是覆上了雪。这些图版是用扩散模型生成的照片;雪景图版是在正午图版上编辑得到的,所以两个视角吻合。

这道食谱解答

  • 怎样给每章不同的照片、颜色或章首页样式?
  • 怎样插入有意留白的页面,或让某一部分从新的跨页开始?
  • 怎样在章首页和空白页上隐藏书眉,或者把空白左页涂成篇的颜色?
  • 怎样排不编号的插图:饰图、小花饰、标志?

简短回答

script.js · 第35–57行在完整代码中
// '{attr.art}' is filled in per heading, so a plain plate names its picture on its line:
// # Noon {style="lamina" art="mediodia" …}. Only the cover and the last plate draw extras.
const PLATES = [ // the style id, its picture, the ink of its caption, anything extra it draws
  { id: 'alba', art: 'alba', extra: (colour) => cover(colour) }, // an arrow: cover() is below
  { id: 'lamina', art: '{attr.art}' }, // any plate on a page of its own
  { id: 'pliego', art: '{attr.art}', half: 'verso' }, // one picture across a spread:
  { id: 'pliego-recto', art: '{attr.art}', half: 'recto' }, // the left half, then the right
  { id: 'nieve', art: 'nieve', ink: 'ink', extra: (colour) => colophon(colour) },
];
const plate = ({ id, art, half, ink = 'white', extra = () => [] }) => ({
  id, span: 'page', // an opener: a span heading always starts a page of its own
  // The left half opens on an even page, a verso, so the right half faces it across the
  // gutter (gotcha: parity-page1-recto).
  ...(half === 'verso' && { breakBefore: { enabled: true, parity: 'even' } }),
  // The picture is as deep as the page, more than the column holds: the plate claims the
  // whole page, and what follows starts on the next one.
  advancedDesign: { enabled: true, slot: { elements: [
    { kind: 'image', id: 'picture', resourceId: art, // the recto half is the same picture,
      placement: at('page', 'top-left', half === 'recto' ? -PAGE.width : 0, 0, // moved left
        { width: mm(half ? 2 * PAGE.width : PAGE.width), height: mm(PAGE.height) }) },
    ...(half === 'recto' ? [] : caption(col(ink))), ...extra(col(ink)),
  ] } },
});

用料

类型
Andada Pro, Syne, Syne Mono(SIL OFL 1.1)
素材
  • alba-1600.jpg
  • atardecer-2000.jpg
  • mediodia-1600.jpg
  • nieve-1600.jpg
  • noche-1600.jpg
  • tormenta-2400.jpg
  • Plate I, dawn: ridges fading into a peach haze under a dark blue sky (Generated With Diffusion Models, 原创)
  • Plate II, noon: a granite cirque and its lake (Generated With Diffusion Models, 原创)
  • Plate III, storm: rain, lightning and a break of sun across a spread (Generated With Diffusion Models, 原创)
  • Plate IV, dusk: the crest lit orange under a violet sky (Generated With Diffusion Models, 原创)
  • Plate V, night: stars over the ridges and a lit refuge (Generated With Diffusion Models, 原创)
  • Plate VI, snow: the cirque of plate II the morning after (Generated With Diffusion Models, 原创)

做法

#1 · 每张图版一个标题样式,由列表生成

代码见上文的简短回答。plate()为PLATES的每一行生成一个标题样式,Markdown则按图版一行一个的方式决定随笔的顺序:# Night {style="lamina" art="noche" n="V" hora="22:10"}。图像元素的resourceId是'{attr.art}',和文字里的占位符一样,所以普通图版都共用lamina样式,在各自的标题行上指明图片;只有封面和最后一张图版要画额外的内容,才各有自己的样式(图像元素)。span: 'page'让每张图版从新的一页开始。图片高210 mm,与页面等高,而设计预留的高度一直到它的图片下边缘为止。这超过了文字页158 mm的栏深,所以图版占去整页,之后的内容从下一页开始,不需要minHeight,也不需要单独的页边距。

跨页的两个样式pliego和pliego-recto画的是同一幅560 mm宽的图,这里是art="tormenta":左页那一半贴页面左边缘,右页那一半再向左移280 mm,这样每页只显示自己的一半,其余部分被画布在成品边缘裁掉。parity: 'even'保证两半相对。如果没有它,从Markdown里拿掉正午图版后,左半会落在第3页(一个右页),右半翻到背面的第4页;有了它,第3页留空,暴风雨仍然铺满第4页和第5页。

#2 · 罗马数字和时刻取自标题行

script.js · 第61–72行在完整代码中
const NUMERAL = { x: 16, y: PAGE.height - 21, size: 13 }; // mm from the top left; size in pt
// A design text's baseline sits 0.8 of its line box below its top: set a smaller label beside
// a larger one this much lower and the two share a baseline.
const dropTo = (big, small, lineHeight = 1.2) => (0.8 * lineHeight * (big - small) * 25.4) / 72;
const caption = (colour) => [
  { kind: 'text', id: 'numeral', content: '{attr.n}', fontFamily: 'Syne', fontWeight: 700,
    fontSize: pt(NUMERAL.size), color: colour, align: 'left',
    placement: at('page', 'top-left', NUMERAL.x, NUMERAL.y) },
  { kind: 'text', id: 'hour', content: '· {attr.hora}', fontFamily: 'Syne Mono', fontSize: pt(8),
    letterSpacing: pt(0.8), color: colour, align: 'left', // the dot: a lone I reads as a bar
    placement: at('#numeral', 'right-of', 1.6, dropTo(NUMERAL.size, 8)) },
];

罗马数字和时刻都是标题属性,所以内容留在Markdown里,一套版面设计适用于所有图版。时刻挂在罗马数字的right-of,两者顶端对齐。设计文字的基线位于元素顶端以下其行框高度的0.8处,行框默认是字号的1.2倍,所以dropTo(13, 8)把时刻下移0.8 × 1.2 × (13 − 8) pt,让8 pt的时刻落在13 pt罗马数字的基线上,距页面顶端193.4 mm。时刻以一个中点开头,和图版IV的题注一样,因为Syne的I只是一道竖线,单独放在时刻旁边会被看成一条线。暴风雨的右半不画题注;雪景图版的题注用墨色,因为它的前景是白色。

#3 · 直接印在图版上的标题和版权页说明

script.js · 第76–90行在完整代码中
const cover = (colour) => [
  { kind: 'text', id: 'title', content: '{title}', fontFamily: 'Syne', fontWeight: 800,
    fontSize: pt(72), lineHeight: 1, letterSpacing: pt(6), textTransform: 'uppercase',
    color: colour, align: 'left', placement: at('page', 'top-left', 22, 26) },
  { kind: 'text', id: 'subtitle', content: '{subtitle}', fontFamily: 'Syne Mono',
    fontSize: pt(10), letterSpacing: pt(2), textTransform: 'uppercase', color: colour,
    align: 'left', placement: at('#title', 'below', 1.5, 3) },
];
// The colophon: one element per line, 10.5 pt apart, so the break falls after the licence, and
// the second line on the baseline of the plate's numeral.
const COLOPHON = { y: NUMERAL.y + dropTo(NUMERAL.size, 7.5), leading: (10.5 * 25.4) / 72 };
const colophon = (colour) => ['colofon', 'tipos'].map((key, line) => ({ kind: 'text', id: key,
  content: `{attr.${key}}`, fontFamily: 'Syne Mono', fontSize: pt(7.5), letterSpacing: pt(0.2),
  color: colour, align: 'right',
  placement: at('page', 'top-right', -16, COLOPHON.y - (1 - line) * COLOPHON.leading) }));

第一张图版就是封面。{title}和{subtitle}读取前置元数据,PLATES中的extra把这两个元素加到这张图版的版面设计里,颜色与它的题注相同。版权页说明以同样的方式放在最后一张图版上,在雪地上用墨色:两个7.5 pt的元素,一行一个,分别取自colofon和tipos属性,右对齐,第二个与罗马数字同一基线。单个自动换行的元素会在宽度用完处随意断开;一行一个元素,断行就落在许可证之后。

#4 · 短文紧随图版,不设分页

script.js · 第94–114行在完整代码中
const textOpener = { enabled: true, slot: { elements: [
  { kind: 'text', id: 'hours', content: '{attr.hora}', fontFamily: 'Syne Mono', fontSize: pt(8),
    letterSpacing: pt(0.8), color: col('accent'), align: 'left',
    placement: at('container', 'top-left', 0, 0) },
  { kind: 'text', id: 'title', content: '{titleText}', fontFamily: 'Syne', fontWeight: 700,
    fontSize: pt(28), lineHeight: 1.05, // a multiple of the size
    color: col('ink'), align: 'left', overflow: 'wrap',
    placement: at('#hours', 'below', 0, 2.5, { width: 'fill' }) },
] } };
// The folio and the book's title under the text block, flush with its left edge, on the
// baseline of the plates' numerals. Not on the plates: a span heading opens their pages, so
// they are opener pages, and 'body' leaves them out.
const foot = (id, content, extra) => ({ kind: 'text', id, content, pages: 'body',
  fontFamily: 'Syne Mono', fontSize: pt(7.5), letterSpacing: pt(0.8), color: col('muted'),
  align: 'left', ...extra });
const FOOT = NUMERAL.y + dropTo(NUMERAL.size, 7.5) - (PAGE.height - MARGIN.bottom); // from the foot
const footer = { elements: [
  foot('folio', '{pageNumber}', { color: col('ink'),
    placement: at('container', 'top-left', 0, FOOT) }),
  foot('book', '{title}', { textTransform: 'uppercase', placement: at('#folio', 'right-of', 5) }),
] };

短文之前的图版占满整页,所以短文不需要自己分页,自然从下一页开始。一页的第一个块若是带分页的标题,这一页就是章首页,页码的pages: 'body'会把它排除。不设分页,文字页就保留页码;而由通栏标题打开的图版页没有页码。breakBefore: { enabled: false }关掉一级标题默认的换到奇数页;有了那次分页,每篇短文所在的页就成了章首页,没有页码。FOOT把页码放在图版罗马数字的基线上,距页面顶端193.4 mm,这样短文的页码和对页图版的罗马数字位于同一条线上。

#5 · 声明所有图版,只引用浮动的那一张

script.js · 第195–221行在完整代码中
// Plate IV is the one plate that floats, so a counter of its type would number it 1. The type
// prints no number (no caption prefix, an empty template) and the caption carries the numeral.
// The text names the plate with :ref's text, since a bare :ref prints 'lámina' and nothing else.
const lamina = { id: 'lamina', name: t({ en: 'Plate', es: 'Lámina' }),
  shortLabel: t({ en: 'plate', es: 'lámina' }), numberingTemplate: '',
  resetOn: 'never', counterFormat: 'decimal', captionPrefix: '' };
// JPEGs in assets/, cut to the page's shape: 1600 × 1200 px for 280 × 210 mm (145 dpi).
const picture = (id, [w, h], alt, extra = {}) => ({ id, typeId: 'lamina', kind: 'bitmap',
  bitmap: { fileId: `${id}-${w}.jpg`, format: 'jpeg', width: w, height: h },
  createdAt: 0, updatedAt: 0, altText: t(alt), ...extra });
const resources = [ // the five the heading styles draw, never cited, and plate IV
  picture('alba', [1600, 1200], { en: 'Eight ridges fading into a peach dawn haze.',
    es: 'Ocho crestas que se pierden en la bruma del alba.' }),
  picture('mediodia', [1600, 1200], { en: 'A granite cirque and its lake under a pale noon sky.',
    es: 'Un circo de granito y su laguna bajo el cielo pálido del mediodía.' }),
  picture('tormenta', [2400, 900], { en: 'A storm over the range: rain on the left, lightning '
    + 'and a break of sun on the right.', es: 'Una tormenta sobre la sierra: lluvia a la '
    + 'izquierda; un rayo y un claro de sol a la derecha.' }),
  picture('noche', [1600, 1200], { en: 'Stars over dark ridges and two lit windows at a refuge.',
    es: 'Estrellas sobre crestas oscuras y dos ventanas encendidas en un refugio.' }),
  picture('nieve', [1600, 1200], { en: 'The cirque the morning after, white with new snow.',
    es: 'El circo a la mañana siguiente, blanco de nieve nueva.' }),
  // 2000 px, 339 mm at the layout's 150 dpi, which the float fits to the 100 mm measure.
  picture('atardecer', [2000, 800], { en: 'A crest lit orange under strips of cloud, violet sky.',
    es: 'Una cresta encendida de naranja bajo franjas de nube, en un cielo violeta.' },
  { caption: t({ en: 'IV · Dusk · 19:41', es: 'IV · Atardecer · 19:41' }) }),
];

设计中的图像元素画的是已声明的资源,所以六张图片都在resources里:食谱assets/中的JPEG,每张按它所填满的页面或跨页的形状裁好,并按像素尺寸声明,版面只读取这个尺寸。loadImage()在构建之前注册每个文件。只有图版IV用:ref引用,因此也只有它浮动。它占据引用之后第一个空闲位置,就在它那篇短文所在的页上,比最后一段低一行。如果是带编号的类型,它的题注会是Plate 1,因为它是该类型中唯一浮动的资源。lamina的numberingTemplate和captionPrefix都为空,因此不会印出Plate.,题注本身以IV开头。句子里由:ref的text说出图版的名字,因为不带参数的:ref只会印出plate这个词。

完整食谱

沙盒
// ═══ Postext Cookbook · Nº 068 · Photo essay with full-bleed plates ═══════════════
// https://postext.dev/en/cookbook/photo-essay-full-bleed
// Code: MIT · Text: original (CC BY 4.0) · Plates: diffusion models
// Fonts: Andada Pro, Syne, Syne Mono (SIL OFL 1.1) · Needs postext ≥ 1.42.1
// Sierra, a landscape photobook: one day in a mountain range in six plates, each on a page of
// its own and one across the gutter of a spread, with three short texts between them.
import {
  buildDocumentWithFonts, renderPageToCanvas, registerResourceImage,
} from 'https://esm.sh/postext';

const LANG = 'es'; // @lang: the language of the sample document ('en' | 'es')
const RECIPE = 'photo-essay-full-bleed';

// ─── 1 · Design ─────────────────────────────────────────────────────────────
// #region palette: the paper between the plates, the ink and one rust for the labels
const palette = {
  ink: '#1c1f27', // text: the blue-black of the night plate
  paper: '#f3f0ea', // every page's ground: a pale stone, seen only between the plates
  accent: '#94462e', // the times over each text: the dusk plate's rust, dark enough for 8 pt
  muted: '#5f646d', // the running foot and the caption of the small plate
  white: '#fbfaf7', // type set on the plates
};
// col() links a colour to its palette entry; the hex is the value the entry holds.
const col = (id) => ({ hex: palette[id], model: 'hex', paletteId: id });
const colorPalette = Object.entries(palette)
  .map(([id, hex]) => ({ id, name: id, value: { hex, model: 'hex' } }));
// #endregion
const PAGE = { width: 280, height: 210 }; // a landscape photobook, in mm
const MARGIN = { top: 28, bottom: 24, inner: 40, outer: 140 }; // text pages: a 100 mm measure
const LEAD = 15; // body leading in pt
const at = (to, edge, x = 0, y = 0, size) => ({ anchor: { to, edge },
  offset: { x: mm(x), y: mm(y) }, ...(size && { size }) });

// #region answer: the plates' heading styles, generated from a list
// '{attr.art}' is filled in per heading, so a plain plate names its picture on its line:
// # Noon {style="lamina" art="mediodia" …}. Only the cover and the last plate draw extras.
const PLATES = [ // the style id, its picture, the ink of its caption, anything extra it draws
  { id: 'alba', art: 'alba', extra: (colour) => cover(colour) }, // an arrow: cover() is below
  { id: 'lamina', art: '{attr.art}' }, // any plate on a page of its own
  { id: 'pliego', art: '{attr.art}', half: 'verso' }, // one picture across a spread:
  { id: 'pliego-recto', art: '{attr.art}', half: 'recto' }, // the left half, then the right
  { id: 'nieve', art: 'nieve', ink: 'ink', extra: (colour) => colophon(colour) },
];
const plate = ({ id, art, half, ink = 'white', extra = () => [] }) => ({
  id, span: 'page', // an opener: a span heading always starts a page of its own
  // The left half opens on an even page, a verso, so the right half faces it across the
  // gutter (gotcha: parity-page1-recto).
  ...(half === 'verso' && { breakBefore: { enabled: true, parity: 'even' } }),

组合好的script.js可以直接运行:把它粘贴到任何页面的模块脚本中,或在CodePen上打开这道食谱。 GitHub上的食谱文件夹 ↗ (在新标签页中打开)

变化

#让图版浮动到条目对页

如果图版要浮动到与图录条目相对的右页,并按比例设定图的宽度,参见与图版相对的图录条目。

#以出血照片开篇的文章

如果照片要出血铺满文章顶部,标题和导语压在照片上,参见杂志专题。

常见问题

易错点

第1页是右页:按物理页码规划页面

第1页是右页(奇数页),第2页是第一个左页(偶数页),所以要按物理页码规划跨页:偶数页上的章首页对着它后面的奇数页。 换页与换栏 →

易错点

SVG插图中不要用<marker>或滤镜(会退回位图)

SVG图只有在不含<marker>、滤镜和蒙版时,才能在PDF中保持矢量;否则会退回位图,而且层层嵌套的滤镜可能让它在Chrome中变成空白。箭头用路径来画。 作为资源的图和表 →

  • 不要引用由版面设计绘制的图版。一旦被引用,它还会作为图浮动:在第一篇短文里:ref正午图版,会在第3页多出一份副本,暴风雨则后移两页,中间隔一个空白页。
  • 黄昏图版位于短文下方一行处,而不在页面底部。在一篇短文的最后一页上,位于文字下方的浮动体会上移到文字处(layout.hugClosingFloats,默认开启),position: 'bottom'在这里不起作用。
  • 每篇短文在两个版本中都调整到正好一页。第一篇若延续到第3页,正午图版会移到第4页,暴风雨移到第6页和第7页,第5页空白。
  • 暴风雨的右半是第二个# Storm标题。页面上不为它印标题,但由标题生成的:::toc会把暴风雨列两次,分别在第4页和第5页。
  • 图版止于成品边缘,也就是画布的边缘。打开page.cutLines后,画布会在成品尺寸四周扩大,每张图版周围的出血区域露出纸色。用于印刷时,把图版锚定到'bleed',并让每张图版在四边各放大一个出血量。

致谢

文本
  • The three texts, the captions and the colophon, in Spanish and English, and the six plates, drawn in code · Postext Cookbook · CC BY 4.0
图片
  • Plate I, dawn: ridges fading into a peach haze under a dark blue sky · Generated With Diffusion Models · 原创
  • Plate II, noon: a granite cirque and its lake · Generated With Diffusion Models · 原创
  • Plate III, storm: rain, lightning and a break of sun across a spread · Generated With Diffusion Models · 原创
  • Plate IV, dusk: the crest lit orange under a violet sky · Generated With Diffusion Models · 原创
  • Plate V, night: stars over the ridges and a lit refuge · Generated With Diffusion Models · 原创
  • Plate VI, snow: the cirque of plate II the morning after · Generated With Diffusion Models · 原创
字体
Andada Pro (SIL OFL 1.1) · Syne (SIL OFL 1.1) · Syne Mono (SIL OFL 1.1)
沙盒