Guest User

Untitled

a guest
Apr 2nd, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1.  
  2. function toBase64(url) {
  3. var canvas = document.createElement("canvas");
  4. var ctx = canvas.getContext('2d');
  5. var img = new Image();
  6. img.src = url;
  7. var height = img.height, width = img.width;
  8. canvas.height = height;
  9. canvas.width = width;
  10. ctx.drawImage(img, 0, 0, width, height);
  11. try {
  12. var dataURL = canvas.toDataURL("image/jpg");
  13. // To prevent ImageMagick from breaking: ONLY SEND BASE64 ENCRYPTED STRING
  14. return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
  15. }
  16. catch (err) { console.log("ERROR " + err);}
  17. }
Advertisement
Add Comment
Please, Sign In to add comment