@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 28 lines 1.15 KB
Raw
1 /**
2 * Anthropic rejects an image over 2000px on a side once a request holds more than 20 images, and
3 * Claude Code forwards images sent into a running turn unchanged, so one large paste breaks
4 * every later request in that thread.
5 */
6 export const IMAGE_ATTACHMENT_MAX_EDGE = 2000;
7
8 export type DownscalableImageMimeType = "image/png" | "image/jpeg";
9
10 export function downscalableImageMimeType(mimeType: string): DownscalableImageMimeType | null {
11 const normalized = mimeType.toLowerCase();
12 if (normalized === "image/png") return "image/png";
13 if (normalized === "image/jpeg" || normalized === "image/jpg") return "image/jpeg";
14 return null;
15 }
16
17 export function fitImageAttachmentSize(size: {
18 readonly width: number;
19 readonly height: number;
20 }): { width: number; height: number } | null {
21 const longestEdge = Math.max(size.width, size.height);
22 if (longestEdge <= IMAGE_ATTACHMENT_MAX_EDGE) return null;
23 const scale = IMAGE_ATTACHMENT_MAX_EDGE / longestEdge;
24 return {
25 width: Math.max(1, Math.min(IMAGE_ATTACHMENT_MAX_EDGE, Math.round(size.width * scale))),
26 height: Math.max(1, Math.min(IMAGE_ATTACHMENT_MAX_EDGE, Math.round(size.height * scale))),
27 };
28 }