I'm trying to use an html file as a source of an image file in <img src="">
tag to avoid mixed-content warning over https while using an http image.
Example:
index.html:
<img src="./image.html" >
image.html:
function getBase64FromImageUrl(url) {
var img = new Image();
img.setAttribute('crossOrigin', 'anonymous');
img.onload = function () {
var canvas = document.createElement("canvas");
canvas.width =this.width;
canvas.height =this.height;
var ctx = canvas.getContext("2d");
ctx.drawImage(this, 0, 0);
var dataURL = canvas.toDataURL("image/png");
dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
document.write(dataURL);
};
img.src = url;
}
getBase64FromImageUrl("http://www.w3schools.com/css/trolltunga.jpg");
<meta http-equiv="Content-type" content="image/png"/>
<!--
I do not want to add any child tags to the body in order to display image from this base64 data. i just want to display using the content headers.
-->
and I'm trying to use the image data that I dump into the html file using javascript now when I tried to open the Html file and I see a string that represents an encoded URL containing the grabbed graphical data but not the actual image as the headers are not set, even though I tried setting the content headers using meta tag in html file, nothing helped. I tried setting the content headers using .httaccess file but no use.
I know it is possible to use any server side script as the content headers that we set are sent from the server along with the response to the http request.
example:
image.php
<?php
header("Content-Type: image/png");
readfile("www.example.com/img.png");
?>
index.html
<img src="./image.php" >
I'm able to do this with php but I actually want to use html and javascript.
The main Idea is to be able to use http images over https without getting a mixed content warning.