Skip to content

Commit 3dfe833

Browse files
authored
ENG-966 - fix Canvas key image sizing (#713)
* fix key image top/bottom padding * Validate image dimensions in calcCanvasNodeSizeAndImg to ensure width and height are finite before proceeding with calculations.
1 parent 8a4f988 commit 3dfe833

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

apps/roam/src/utils/calcCanvasNodeSizeAndImg.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,17 @@ const calcCanvasNodeSizeAndImg = async ({
124124
}
125125
if (!imageUrl) return { w, h, imageUrl: "" };
126126

127-
const padding = Number(DEFAULT_STYLE_PROPS.padding.replace("px", ""));
128-
const maxWidth = Number(MAX_WIDTH.replace("px", ""));
129-
const effectiveWidth = maxWidth - 2 * padding;
130-
131127
try {
132128
const { width, height } = await loadImage(imageUrl);
129+
if (!width || !height || !Number.isFinite(width) || !Number.isFinite(height)) {
130+
return { w, h, imageUrl: "" };
131+
}
132+
133133
const aspectRatio = width / height;
134-
const nodeImageHeight = effectiveWidth / aspectRatio;
134+
const nodeImageHeight = w / aspectRatio;
135+
const newHeight = h + nodeImageHeight;
135136

136-
return { w, h: h + nodeImageHeight + padding * 2, imageUrl };
137+
return { w, h: newHeight, imageUrl };
137138
} catch {
138139
renderToast({
139140
id: "tldraw-image-load-fail",

0 commit comments

Comments
 (0)