function getBase64ImageFromUrl(image_url){ var canvas = document.createElement("canvas"); var ctx = canvas.getContext("2d"); var img = new Image(); img.src = image_url; canvas.width = img.width; canvas.height = img.height; ctx.drawImage(img, 0, 0); var data = canvas.toDataURL("image/jpeg");
return data;
}
OR
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
var img = new Image();
img.onload = function () {
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
var data = canvas.toDataURL("image/jpeg");
alert(data);
};
img.src = "http://localhost/MvcApplication3/test.png";
OR
function getBase64ImageFromUrl(image_url){
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
var img = new Image(); img.src = image_url;
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0);
var data = canvas.toDataURL("image/jpeg");
return data;}
imgObj = $(this).parent().find('img');img = getBase64ImageFromUrl(imgObj[0].src)
function getBase64ImageFromUrl(image_url){ var canvas = document.createElement("canvas"); var ctx = canvas.getContext("2d"); var img = new Image(); img.src = image_url; canvas.width = img.width; canvas.height = img.height; ctx.drawImage(img, 0, 0); var data = canvas.toDataURL("image/jpeg"); return data;}