Skip to content

Instantly share code, notes, and snippets.

@omar2205
Created July 2, 2024 12:52
Show Gist options
  • Save omar2205/6d0b31406863e8b86ce7efe533aa6b5c to your computer and use it in GitHub Desktop.
Save omar2205/6d0b31406863e8b86ce7efe533aa6b5c to your computer and use it in GitHub Desktop.
draw image on canvas
function drawImageFromUrl(url, canvasId, x = 0, y = 0) {
    const canvas = document.getElementById(canvasId)
    const ctx = canvas.getContext('2d')
    const img = new Image()
    
    img.onload = function() {
        ctx.drawImage(img, x, y)
    }

    img.src = url
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment