Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function toBase64(url) {
- var canvas = document.createElement("canvas");
- var ctx = canvas.getContext('2d');
- var img = new Image();
- img.src = url;
- var height = img.height, width = img.width;
- canvas.height = height;
- canvas.width = width;
- ctx.drawImage(img, 0, 0, width, height);
- try {
- var dataURL = canvas.toDataURL("image/jpg");
- // To prevent ImageMagick from breaking: ONLY SEND BASE64 ENCRYPTED STRING
- return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
- }
- catch (err) { console.log("ERROR " + err);}
- }
Advertisement
Add Comment
Please, Sign In to add comment