Add review window and manual content generation
This commit is contained in:
@@ -11,6 +11,19 @@ import { IMAGE_PROMPT_MAX, IMAGE_SIZES, type ImageSizeKey } from "@/lib/ai/image
|
||||
|
||||
type OverlayPos = "top" | "center" | "bottom";
|
||||
|
||||
let sarabunFontPromise: Promise<FontFace> | null = null;
|
||||
|
||||
function loadSarabunFont() {
|
||||
if (!sarabunFontPromise) {
|
||||
const font = new FontFace("Sarabun", `url(${withBase("/fonts/sarabun/Sarabun-Bold.ttf")})`, { weight: "700" });
|
||||
sarabunFontPromise = font.load().then((loaded) => {
|
||||
document.fonts.add(loaded);
|
||||
return loaded;
|
||||
});
|
||||
}
|
||||
return sarabunFontPromise;
|
||||
}
|
||||
|
||||
function wrapText(ctx: CanvasRenderingContext2D, text: string, maxWidth: number): string[] {
|
||||
const lines: string[] = [];
|
||||
const paragraphs = text.split("\n");
|
||||
@@ -34,7 +47,8 @@ function wrapText(ctx: CanvasRenderingContext2D, text: string, maxWidth: number)
|
||||
function buildComposite(imgUrl: string, text: string, pos: OverlayPos): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
img.onload = async () => {
|
||||
try { await loadSarabunFont(); } catch { /* Canvas will use the Thai fallback font. */ }
|
||||
const canvas = document.createElement("canvas");
|
||||
canvas.width = img.naturalWidth;
|
||||
canvas.height = img.naturalHeight;
|
||||
@@ -57,15 +71,15 @@ function buildComposite(imgUrl: string, text: string, pos: OverlayPos): Promise<
|
||||
|
||||
const grad = ctx.createLinearGradient(0, zoneY, 0, zoneY + zoneH);
|
||||
if (pos === "top") {
|
||||
grad.addColorStop(0, "rgba(0,0,0,0.75)");
|
||||
grad.addColorStop(0, "rgba(0,0,0,0.48)");
|
||||
grad.addColorStop(1, "rgba(0,0,0,0)");
|
||||
} else if (pos === "bottom") {
|
||||
grad.addColorStop(0, "rgba(0,0,0,0)");
|
||||
grad.addColorStop(1, "rgba(0,0,0,0.75)");
|
||||
grad.addColorStop(1, "rgba(0,0,0,0.48)");
|
||||
} else {
|
||||
grad.addColorStop(0, "rgba(0,0,0,0)");
|
||||
grad.addColorStop(0.15, "rgba(0,0,0,0.65)");
|
||||
grad.addColorStop(0.85, "rgba(0,0,0,0.65)");
|
||||
grad.addColorStop(0.15, "rgba(0,0,0,0.42)");
|
||||
grad.addColorStop(0.85, "rgba(0,0,0,0.42)");
|
||||
grad.addColorStop(1, "rgba(0,0,0,0)");
|
||||
}
|
||||
ctx.fillStyle = grad;
|
||||
@@ -73,7 +87,7 @@ function buildComposite(imgUrl: string, text: string, pos: OverlayPos): Promise<
|
||||
|
||||
ctx.fillStyle = "#ffffff";
|
||||
ctx.textAlign = "center";
|
||||
ctx.shadowColor = "rgba(0,0,0,0.55)";
|
||||
ctx.shadowColor = "rgba(0,0,0,0.35)";
|
||||
ctx.shadowBlur = fontSize * 0.28;
|
||||
ctx.shadowOffsetY = 2;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user