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
This commit is contained in:
@@ -8,8 +8,9 @@ import { join } from "node:path";
|
||||
|
||||
import { ImageResponse } from "next/og";
|
||||
|
||||
import { coverBox } from "./celebrityPhoto";
|
||||
import type { ChartResult } from "./types";
|
||||
import { wheelSvg } from "./wheelSvg";
|
||||
import { LABEL_STYLE, WHEEL_UNITS, wheelSvg } from "./wheelSvg";
|
||||
|
||||
const W = 1200;
|
||||
const H = 630;
|
||||
@@ -43,6 +44,53 @@ function loadFonts() {
|
||||
*/
|
||||
export const printable = (s: string) => s.replace(/[^\p{L}\p{N}\p{P}\p{Zs}+=<>°]/gu, "");
|
||||
|
||||
/**
|
||||
* The chart wheel, `size` pixels: the SVG image without its labels, and the
|
||||
* labels drawn on top with the card's fonts (inside an SVG image the renderer
|
||||
* has no fonts, so glyphs and numbers would come out as boxes).
|
||||
*/
|
||||
function Wheel({ chart, timeKnown, size }: { chart: ChartResult; timeKnown: boolean; size: number }) {
|
||||
const { svg, labels } = wheelSvg(chart, timeKnown, size);
|
||||
const k = size / WHEEL_UNITS;
|
||||
return (
|
||||
<div style={{ display: "flex", position: "relative", width: size, height: size }}>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={`data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`} width={size} height={size} alt="" />
|
||||
{labels.map((l, i) => {
|
||||
const style = l.className.split(" ").map((c) => LABEL_STYLE[c]).find(Boolean);
|
||||
if (!style) return null;
|
||||
const fontSize = style.size * k;
|
||||
const w = fontSize * 6;
|
||||
const h = fontSize * 1.4;
|
||||
return (
|
||||
<div
|
||||
key={i}
|
||||
style={{
|
||||
display: "flex",
|
||||
position: "absolute",
|
||||
left: l.x * k - w / 2,
|
||||
top: l.y * k - h / 2,
|
||||
width: w,
|
||||
height: h,
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
fontFamily: style.font,
|
||||
fontWeight: style.weight,
|
||||
fontSize,
|
||||
lineHeight: 1,
|
||||
color: style.color,
|
||||
// No undefined values: the renderer stumbles on them.
|
||||
...(style.halo ? { textShadow: "0 0 3px #111729" } : {}),
|
||||
}}
|
||||
>
|
||||
{style.font === "DejaVu Sans" ? l.text : printable(l.text)}
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export interface CardLine {
|
||||
/** A zodiac or planet glyph (DejaVu Sans has them all). */
|
||||
glyph: string;
|
||||
@@ -67,18 +115,11 @@ export async function chartCard({
|
||||
lines: CardLine[];
|
||||
cacheControl: string;
|
||||
}): Promise<Response> {
|
||||
const svg = wheelSvg(chart, timeKnown, WHEEL);
|
||||
return new ImageResponse(
|
||||
(
|
||||
<div style={{ display: "flex", width: W, height: H, background: "#0d1220", color: "#ece6d8", fontFamily: "Inter" }}>
|
||||
<div style={{ display: "flex", width: WHEEL + 40, height: H, alignItems: "center", justifyContent: "center" }}>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={`data:image/svg+xml;base64,${Buffer.from(svg).toString("base64")}`}
|
||||
width={WHEEL}
|
||||
height={WHEEL}
|
||||
alt=""
|
||||
/>
|
||||
<Wheel chart={chart} timeKnown={timeKnown} size={WHEEL} />
|
||||
</div>
|
||||
<div style={{ display: "flex", flexDirection: "column", flex: 1, padding: "56px 56px 44px 8px", gap: 18 }}>
|
||||
<div style={{ display: "flex", fontSize: 17, fontWeight: 600, letterSpacing: 2.5, color: "#d9b46a" }}>
|
||||
@@ -107,3 +148,84 @@ export async function chartCard({
|
||||
{ width: W, height: H, fonts: await loadFonts(), headers: { "Cache-Control": cacheControl } },
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A famous person's preview image: the photo on the left (cropped around the
|
||||
* face point), the name, the Sun, Moon and Ascendant and the chart wheel on
|
||||
* the right. `photo`: the stored JPEG as bytes, with its size and face point.
|
||||
*/
|
||||
export async function celebrityCard({
|
||||
chart,
|
||||
timeKnown,
|
||||
name,
|
||||
subtitle,
|
||||
lines,
|
||||
photo,
|
||||
cacheControl,
|
||||
}: {
|
||||
chart: ChartResult;
|
||||
timeKnown: boolean;
|
||||
name: string;
|
||||
subtitle: string | null;
|
||||
lines: CardLine[];
|
||||
photo: { data: ArrayBuffer; width: number; height: number; focus_x: number; focus_y: number } | null;
|
||||
cacheControl: string;
|
||||
}): Promise<Response> {
|
||||
const PHOTO_W = 440;
|
||||
const RING = 400;
|
||||
const box = photo && coverBox(photo, PHOTO_W, H);
|
||||
return new ImageResponse(
|
||||
(
|
||||
<div style={{ display: "flex", width: W, height: H, background: "#0d1220", color: "#ece6d8", fontFamily: "Inter" }}>
|
||||
{photo && box && (
|
||||
<div style={{ display: "flex", position: "relative", width: PHOTO_W, height: H, overflow: "hidden" }}>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={`data:image/jpeg;base64,${Buffer.from(photo.data).toString("base64")}`}
|
||||
width={box.width}
|
||||
height={box.height}
|
||||
style={{ position: "absolute", left: box.left, top: box.top }}
|
||||
alt=""
|
||||
/>
|
||||
<div
|
||||
style={{
|
||||
position: "absolute",
|
||||
right: 0,
|
||||
top: 0,
|
||||
width: 90,
|
||||
height: H,
|
||||
background: "linear-gradient(90deg, rgba(13,18,32,0) 0%, #0d1220 100%)",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div style={{ display: "flex", flexDirection: "column", flex: 1, padding: "44px 48px 36px 36px" }}>
|
||||
<div style={{ display: "flex", fontSize: 17, fontWeight: 600, letterSpacing: 2.5, color: "#d9b46a" }}>
|
||||
HÍRES EMBEREK HOROSZKÓPJA
|
||||
</div>
|
||||
<div style={{ display: "flex", fontFamily: "Cormorant Garamond", fontSize: 58, lineHeight: 1.05, marginTop: 12 }}>
|
||||
{printable(name)}
|
||||
</div>
|
||||
{subtitle && (
|
||||
<div style={{ display: "flex", fontSize: 22, color: "#c9cfdc", marginTop: 6 }}>{printable(subtitle)}</div>
|
||||
)}
|
||||
<div style={{ display: "flex", flex: 1, alignItems: "center", gap: 28, marginTop: 8 }}>
|
||||
<Wheel chart={chart} timeKnown={timeKnown} size={RING} />
|
||||
<div style={{ display: "flex", flexDirection: "column", gap: 14, fontSize: 24, color: "#c9cfdc" }}>
|
||||
{lines.map((l) => (
|
||||
<div key={l.label} style={{ display: "flex", alignItems: "center", gap: 10 }}>
|
||||
<span style={{ fontFamily: "DejaVu Sans", color: "#d9b46a" }}>{l.glyph.replace(/︎/g, "")}</span>
|
||||
<span>{printable(l.label)}</span>
|
||||
</div>
|
||||
))}
|
||||
<div style={{ display: "flex", fontFamily: "Cormorant Garamond", fontSize: 32, color: "#ece6d8", marginTop: 18 }}>
|
||||
sors<span style={{ color: "#d9b46a" }}>fonalak</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
),
|
||||
{ width: W, height: H, fonts: await loadFonts(), headers: { "Cache-Control": cacheControl } },
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user