Created
August 5, 2014 05:20
-
-
Save yangxing-star/06346860a66b42691661 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
var img = new Image(); | |
img.crossOrigin = "*"; | |
img.src = "http://s3.steedos.com/users/5194c74a8e296a6cfe000019/admin/angel_galaxy-wallpaper-1440x900.jpg"; | |
var canvas = document.createElement("canvas"); | |
canvas.width = img.width; | |
canvas.height = img.width; | |
var ctx = canvas.getContext("2d"); | |
ctx.fillRect(50,50,50,50); | |
img.onload = function() { | |
ctx.drawImage(img, 0, 0); | |
var g = ctx.canvas.toDataURL("image/jpeg", 1); | |
document.getElementById('test').value = g; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment