Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
rudolfs committed Feb 12, 2025
1 parent 9231d3c commit 5df28da
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/components/Markdown.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@
}) as string,
);
}
function getImageSize(
url: string,
callback: (size: { width: number; height: number }) => void,
) {
const img = new Image();
img.onload = function () {
callback({ width: img.width, height: img.height });
};
img.onerror = function () {
console.error("Failed to load image");
};
img.src = url; // Ensure this is a valid PNG image URL
}
$effect(() => {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
Expand Down Expand Up @@ -90,6 +103,10 @@
// Embed an img element below the link
if (mimeType?.startsWith("image")) {
const element = document.createElement("img");
getImageSize(url, size => {
console.log({ size });
element.style.width = `${size.width / 2}px`;
});
element.setAttribute("src", url);
element.style.display = "block";
e.style.display = "block";
Expand Down

0 comments on commit 5df28da

Please sign in to comment.