Convert image from url to Base64

✔ Recommended Answer

HTML

<img id="imageid" src="https://www.google.de/images/srpr/logo11w.png">

JavaScript

function getBase64Image(img) {  var canvas = document.createElement("canvas");  canvas.width = img.width;  canvas.height = img.height;  var ctx = canvas.getContext("2d");  ctx.drawImage(img, 0, 0);  var dataURL = canvas.toDataURL("image/png");  return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");}var base64 = getBase64Image(document.getElementById("imageid"));

This method requires the canvas element, which is perfectly supported.

Source: stackoverflow.com

Answered By: ˈvɔlə

Comments

Most Popular

Remove Unicode Zero Width Space PHP

PhpStorm, return value is expected to be 'A', 'object' returned

Laravel file upload returns forbidden 403, file permission is 700 not 755