保存图像标签中的图像不上传

保存图像标签中的图像不上传

问题描述:

I have a google map on my site, I am taking screenshots of it, and storing that in image tags below the map for the user to see.

How can I get the images from those tags and pass them through the form to store them on the PHP Server?

enter image description here

我的网站上有一个谷歌地图,我正在截取它,并将其存储在下面的图像标签中 地图供用户查看。 p>

如何从这些标签中获取图像并将其传递到表单中以将其存储在PHP服务器上? p>

p> div>

Use a canvas to process the image and get it as a base64 dataurl in a text input of your form:

// img is your image tag
var processCanvas = document.createElement("canvas");
processCanvas.width = img.width;
processCanvas.height = img.height;
processCanvas.getContext("2d").drawImage(img, 0, 0);

// you need to have an <input id=textInput' /> in your form
var textInput = document.getElementById('textInput');
textInput.value = processCanvas.toDataURL('image/jpeg');

Submit your image by posting the form.

</div>