Files
sorsfonalak/services/frontend/src/lib/celebrityPhoto.ts
T
fecoandClaude Opus 5.5 37cb0abf4b
CI / test (push) Successful in 2m21s
CI / build (push) Skipped
CI / deploy (push) Skipped
Famous people: admin page, own prompt, one photo, public pages
- Admin "Híres emberek": birth data, one photo (S3: DigitalOcean Spaces in
  production, RustFS in development), a face point that every crop keeps
  in view, publishing, and a detailed portrait written with its own
  `celebrity` prompt (third person, by name, from the chart alone).
- The photo is stored once (upright JPEG, at most 2000 px, no metadata);
  next/image makes the sizes from it, so Cloudflare can cache those.
- Public list and pages (/hires-emberek), in the sitemap, with a share
  image showing the face and the chart.
- Share images: the wheel's glyphs and numbers are drawn with the card's
  fonts (inside the SVG image they came out as boxes, on every card).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
2026-11-22 16:08:35 +00:00

37 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// A famous person's photo: one stored version, served by the backend through
// the /api/v1 proxy; next/image makes the sized versions from it (and
// Cloudflare caches those), so no sizes are stored.
import type { CelebrityPhoto } from "./types";
/** The stored photo's address on this site (also the source of next/image). */
export function photoSrc(photo: Pick<CelebrityPhoto, "key">): string {
return `/api/v1/public/photos/${photo.key.split("/").map(encodeURIComponent).join("/")}`;
}
/** CSS `object-position` that keeps the face point in view when the photo is cropped. */
export function objectPosition(photo: Pick<CelebrityPhoto, "focus_x" | "focus_y">): string {
return `${(photo.focus_x * 100).toFixed(1)}% ${(photo.focus_y * 100).toFixed(1)}%`;
}
/**
* Where a `width`×`height` photo goes in a `boxW`×`boxH` frame so that it
* covers it with the face point as near the middle as the edges allow (for
* the preview image, whose renderer has no object-position).
*/
export function coverBox(
photo: Pick<CelebrityPhoto, "width" | "height" | "focus_x" | "focus_y">,
boxW: number,
boxH: number,
): { width: number; height: number; left: number; top: number } {
const scale = Math.max(boxW / photo.width, boxH / photo.height);
const width = Math.ceil(photo.width * scale);
const height = Math.ceil(photo.height * scale);
const clamp = (v: number, min: number) => Math.round(Math.min(0, Math.max(min, v)));
return {
width,
height,
left: clamp(boxW / 2 - photo.focus_x * width, boxW - width),
top: clamp(boxH / 2 - photo.focus_y * height, boxH - height),
};
}