Created
December 24, 2018 09:05
-
-
Save ClausClaus/2561b1d4d0e5e3f4ed811b45900ba48a to your computer and use it in GitHub Desktop.
将图片转化成base64
This file contains 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 getBase64Image(img, width, height) { | |
var canvas = document.createElement('canvas') | |
canvas.width = width ? width : img.width | |
canvas.height = height ? height : img.height | |
var ctx = canvas.getContext('2d') | |
ctx.drawImage(img, 0, 0, canvas.width, canvas.height) | |
var dataURL = canvas.toDataURL() | |
return dataURL | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment