Skip to content

renderImage()

Loads a resource into a new HTMLImageElement: src is set via blobToUrl (so blobs get object URLs, strings are used directly). Resolves on load with the same element; rejects on error (e.g. bad URL, network failure, corrupt image) with no rejection value.

Does not add the node to the DOM — use the returned element for canvas, measuring, or imageToBlob.

Examples:

ts
const img = await renderImage('https://example.com/pic.png');
document.body.appendChild(img);
ts
const img = await renderImage(pickedFile);
const blob = imageToBlob(img, 'image/webp');

Released under the MIT License.