<html lang="ru">
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="" />
</head>
<body>
<img id="bannerImg" src="http://i.mycdn.me/i?r=AzGBqNaF5OQp2lMpnhRx4DEF6n4GIK-fj2ZRG4FZpDcQFF2nfVKdvp0RnpOmdvULI2k" />
<p><a href="page2.html">Go to page 2</a></p>
<script type="text/javascript">
function getBase64Image(img) {
let canvas = document.createElement("canvas");
canvas.width = img.width;
canvas.height = img.height;
let ctx = canvas.getContext("2d");
ctx.drawImage(img, 0, 0);
let dataURL = canvas.toDataURL("image/png");
return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
}
function getBase64ImageById(id){
return getBase64Image(document.getElementById(id));
}
console.log(getBase64ImageById("bannerImg"));
</script>
</body>
</html> |