我想使用html2canvas获取屏幕截图。它工作正常的文本,但它不是呈现CDN图像,如果我托管图像在服务器中工作正常,但如果试图加载图像从CDN链接那些图像不呈现。html2canvas不呈现CDN图像
我的代码是:
的index.php
function capture() {
$('#target').html2canvas({
onrendered: function (canvas) {
var img = canvas.toDataURL();
console.log(img);
$('',{src:img}).appendTo($('img'));
//Set hidden field's value to image data (base-64 string)
$('#img_val').val(canvas.toDataURL("image/png"));
//Submit the form manually
document.getElementById("myForm").submit();
}
});
}
Save.php
//Get the base-64 string from data
$filteredData=substr($_POST['img_val'], strpos($_POST['img_val'], ",")+1);
//Decode the string
$unencodedData=base64_decode($filteredData);
echo $filteredData;
//Save the image
file_put_contents('img.png', $unencodedData);
?>
Save the image and show to user
Click Here to See The Image Saved to Server | Click Here to Go Back |
Here is Client-sided image: //Show the image echo ' ?> |
+0
更可能有一个跨域请求,在某个地方,这是被禁止的。检查您的JavaScript控制台是否有错误。 –