function loadImage(url: string): Promise { return new Promise(resolve => { const image = new Image(); image.onload = function() { resolve(image); } image.crossOrigin = 'anonymous'; image.src = url; }); } export async function drawSourceImage(url: string) { const sourceCanvas = document.getElementById('source') as HTMLCanvasElement; const sourceContext = sourceCanvas.getContext('2d')!; const resultCanvas = document.getElementById('result') as HTMLCanvasElement; const image = await loadImage(url); const ratio = Math.min(500 / image.width, 500 / image.height); const width = Math.round(ratio * image.width); const height = Math.round(ratio * image.height); sourceCanvas.width = width; sourceCanvas.height = height; sourceContext.drawImage(image, 0, 0, image.width, image.height, 0, 0, width, height); }