36 lines
1.5 KiB
TypeScript
36 lines
1.5 KiB
TypeScript
export type ImageSizePreset = {
|
|
label: string;
|
|
width: number;
|
|
height: number;
|
|
paper?: "a4";
|
|
};
|
|
|
|
// A4 is 70:99, not 3:4. These dimensions keep reference-image generation
|
|
// below the 2048² pixel budget. This is a generation preset, not print export.
|
|
export const imageSizePresets: ImageSizePreset[] = [
|
|
{ label: "1:1", width: 2048, height: 2048 },
|
|
{ label: "4:3", width: 2304, height: 1728 },
|
|
{ label: "3:4", width: 1728, height: 2304 },
|
|
{ label: "16:9", width: 2560, height: 1440 },
|
|
{ label: "9:16", width: 1440, height: 2560 },
|
|
{ label: "A4 竖版", width: 1680, height: 2376, paper: "a4" },
|
|
{ label: "A4 横版", width: 2376, height: 1680, paper: "a4" }
|
|
];
|
|
|
|
export function imageDimensionsForEngine(size: Pick<ImageSizePreset, "width" | "height">, engine: string) {
|
|
// EvoLink ignores resolution for explicit pixels. Stay within its existing
|
|
// 1K budget and align to 16px; the resulting A4 ratio differs by < 0.06%.
|
|
if (engine === "evolink") {
|
|
if (size.width === 1680 && size.height === 2376) return { width: 848, height: 1200 };
|
|
if (size.width === 2376 && size.height === 1680) return { width: 1200, height: 848 };
|
|
}
|
|
return { width: size.width, height: size.height };
|
|
}
|
|
|
|
export function imageSizePresetFromDimensions(width?: number, height?: number) {
|
|
return imageSizePresets.find((size) => {
|
|
const evo = imageDimensionsForEngine(size, "evolink");
|
|
return size.width === width && size.height === height || evo.width === width && evo.height === height;
|
|
});
|
|
}
|