Created
November 15, 2022 17:03
-
-
Save andreasvirkus/a813132542b38ff421aa0b83cc27e771 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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