feat(website): photos upright, without metadata, in responsive sizes

Every upload is turned upright, stripped of its metadata (EXIF, GPS),
kept at most 2400 px wide and saved at 480/960/1600 px in WebP and
JPEG; the pages pick the size with <picture> and srcset. Every file
counts towards storage; a photo that can't be read is refused. sharp
0.35 (prebuilt, no build step on the servers).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 14:04:43 +02:00
co-authored by Claude Opus 5.5
parent 6be1a2782d
commit 2ba755145d
13 changed files with 153 additions and 37 deletions
+15 -2
View File
@@ -3,13 +3,26 @@ import type { Image } from "./types";
export const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");
/**
* An uploaded image at the size the screen needs (§3: responsive sizes in WebP and JPEG): the
* browser picks from the `srcset`s by `sizes`. `alt` overrides the image's own (e.g. "" when it's
* only decoration behind text).
*/
export function Picture({ image, className, sizes = "100vw", priority = false, alt }: { image: Image; className?: string; sizes?: string; priority?: boolean; alt?: string }) {
const img = (
<img src={image.url} srcSet={image.srcset?.jpg} sizes={image.srcset ? sizes : undefined} alt={alt ?? image.alt}
width={image.width ?? undefined} height={image.height ?? undefined}
loading={priority ? "eager" : "lazy"} fetchPriority={priority ? "high" : undefined} decoding="async" className={className} />
);
return image.srcset ? <picture><source type="image/webp" srcSet={image.srcset.webp} sizes={sizes} />{img}</picture> : img;
}
/** An image in a frame (Heritage frames, duotone tints), or a soft placeholder when there's none. */
export function Img({ image, className, sizes = "(min-width: 768px) 50vw, 100vw", priority = false, ratio = "aspect-[4/3]" }: { image: Image | null; className?: string; sizes?: string; priority?: boolean; ratio?: string }) {
return (
<div className={cx("cc-frame", ratio, className)}>
{image ? (
<img src={image.url} alt={image.alt} sizes={sizes} width={image.width ?? undefined} height={image.height ?? undefined}
loading={priority ? "eager" : "lazy"} fetchPriority={priority ? "high" : undefined} decoding="async" className="cc-img" />
<Picture image={image} sizes={sizes} priority={priority} className="cc-img" />
) : (
<div aria-hidden="true" className="h-full w-full bg-gradient-to-br from-brand/25 via-brand-tint to-accent/30" />
)}
@@ -5,7 +5,7 @@
* photo.
*/
import { media } from "../load";
import { Button, cx, Img, type ButtonData } from "../parts";
import { Button, cx, Img, Picture, type ButtonData } from "../parts";
import type { Image, SectionProps } from "../types";
type HeroData = { headline: string; subline: string | null; images: string[]; videoId: string | null; button: ButtonData };
@@ -24,7 +24,7 @@ function Words({ d, centred, light, size = "cc-h1" }: { d: HeroData; centred?: b
function Video({ video, still, className }: { video: Image | null; still: Image | null; className?: string }) {
return (
<div className={cx("relative h-full w-full", className)}>
{still ? <img src={still.url} alt={still.alt} className="cc-img absolute inset-0" fetchPriority="high" /> : <div className="absolute inset-0 bg-brand" />}
{still ? <Picture image={still} priority className="cc-img absolute inset-0" /> : <div className="absolute inset-0 bg-brand" />}
{video && (
<video className="cc-motion cc-img absolute inset-0 hidden sm:block" src={video.url} poster={still?.url} autoPlay muted loop playsInline aria-hidden="true" />
)}
@@ -79,7 +79,7 @@ export function Hero({ section, site, template }: SectionProps) {
if (template === "bold") {
return (
<section className="cc-section-hero grid bg-gray-950 text-white md:min-h-[80vh] md:grid-cols-2">
<div className="relative min-h-[50vh] md:order-2">{first && <img src={first.url} alt={first.alt} className="cc-img absolute inset-0" fetchPriority="high" />}</div>
<div className="relative min-h-[50vh] md:order-2">{first && <Picture image={first} sizes="(min-width: 768px) 50vw, 100vw" priority className="cc-img absolute inset-0" />}</div>
<div className="flex flex-col justify-center px-6 pb-16 pt-32 sm:px-12"><Words d={d} light /></div>
</section>
);
@@ -100,7 +100,7 @@ export function Hero({ section, site, template }: SectionProps) {
return (
<Fullbleed d={d} site={site}>
<div className="grid h-full grid-cols-3 gap-1">
{three.map((im, i) => <div key={i} className="relative">{im ? <img src={im.url} alt={im.alt} className="cc-img absolute inset-0" /> : <div className="absolute inset-0 bg-brand/60" />}</div>)}
{three.map((im, i) => <div key={i} className="relative">{im ? <Picture image={im} sizes="34vw" priority={i === 0} className="cc-img absolute inset-0" /> : <div className="absolute inset-0 bg-brand/60" />}</div>)}
</div>
</Fullbleed>
);
@@ -134,7 +134,7 @@ export function Hero({ section, site, template }: SectionProps) {
}
// photo (and video, drawn the same way with its loop).
const visual = variant === "video" ? <Video video={video} still={first} /> : first ? <img src={first.url} alt={first.alt} className="cc-img absolute inset-0" fetchPriority="high" /> : null;
const visual = variant === "video" ? <Video video={video} still={first} /> : first ? <Picture image={first} priority className="cc-img absolute inset-0" /> : null;
if (template === "bold") return <Fullbleed d={d} site={site}>{visual ?? <div className="h-full w-full bg-brand" />}</Fullbleed>;
if (template === "heritage") {
return (
@@ -4,7 +4,7 @@
*/
import { MessagePlayer } from "../MessagePlayer";
import { media, str, t } from "../load";
import { Button, cx, DateBadge, dayName, fmtDate, fmtTime, Img, Paragraphs, SectionHeading, type ButtonData } from "../parts";
import { Button, cx, DateBadge, dayName, fmtDate, fmtTime, Img, Paragraphs, Picture, SectionHeading, type ButtonData } from "../parts";
import type { SectionProps, SiteEvent } from "../types";
import { Hero } from "./Hero";
@@ -394,7 +394,7 @@ function Invitation(p: SectionProps) {
const img = media(p.site, d.imageId);
return (
<section className="cc-section cc-own-bg cc-dark relative isolate overflow-hidden bg-gray-900 text-white">
{img && <img src={img.url} alt="" className="cc-img absolute inset-0 -z-10" loading="lazy" />}
{img && <Picture image={img} alt="" className="cc-img absolute inset-0 -z-10" />}
<div className="absolute inset-0 -z-10 bg-black/60" aria-hidden="true" />
<div className="cc-wrap py-10 text-center">
<h2 className="cc-h2">{d.heading}</h2>
+2 -1
View File
@@ -6,7 +6,8 @@ import type { Church } from "@crosscode/contracts";
export type Template = "heritage" | "bold" | "community" | "clean";
export type Image = { url: string; alt: string; width: number | null; height: number | null };
/** An uploaded image; `srcset` lists its responsive sizes (WebP and JPEG) when it has them. */
export type Image = { url: string; alt: string; width: number | null; height: number | null; srcset?: { webp: string; jpg: string } };
export type Section = { type: string; variant: string | null; data: Record<string, unknown> };