Skip to content

Instantly share code, notes, and snippets.

@andreasvirkus
Created November 15, 2022 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreasvirkus/a813132542b38ff421aa0b83cc27e771 to your computer and use it in GitHub Desktop.
Save andreasvirkus/a813132542b38ff421aa0b83cc27e771 to your computer and use it in GitHub Desktop.
function resizeImage(el, width, height, quality) {
var canvas = document.createElement('canvas')
canvas.width = width
canvas.height = height
var context = canvas.getContext('2d')
context.drawImage(el, 0, 0, width, height)
try {
return canvas.toDataURL('image/jpeg', quality)
} catch (e) {
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment