[英]html2canvas capturing div image
im working on my wordpress site in which i want a div to be converted to image.. im using html2canvas javascript and it works perfect.我在我的 wordpress 网站上工作,我希望将一个 div 转换为图像。我使用 html2canvas javascript,它工作得很好。 when i capture a post it saves it to the server has "Captured.jpg".
当我捕获一个帖子时,它会将其保存到服务器上,并带有“Captured.jpg”。 all good till here.. but when i click capture again on a different post it replaces the previous image "captured.jpg".
一切都很好,直到这里..但是当我在不同的帖子上再次单击捕获时,它会替换之前的图像“captured.jpg”。 i want all the images of the posts that i capture to be saved on server with post names may be?
我希望我捕获的所有帖子图像都保存在带有帖子名称的服务器上? is it possible?
是否可以?
Header标题
<script type="text/javascript">
function capture() {
$("#quotesingle").html2canvas({
canvas: hidden_screenshot,
onrendered: function() {
var img = $("#hidden_screenshot")[0].toDataURL();
img= img.replace('data:image/png;base64','');
$form = '<form name="frmact" action="result.php" method="post" ><input type="hidden" name="img" value="' + img + '" /></form>';
$('body').append($form);
frmact.submit();
$('body').remove($form);
}
});
}
</script>
Results.php结果.php
<?php
$canvasImg = $_POST['img'];
$data = base64_decode($canvasImg);
$File = "captured.jpg";
$Handle = fopen($File, 'w');
fwrite($Handle, $data);
fclose($Handle);
?>
captured.jpg is saved.捕获的.jpg 被保存。
single.php单个.php
//POSTLOOP
<input type=button value="Screenshot" onclick="javascript:capture();" /><br /><br /></div>
<canvas id="hidden_screenshot" style="display:none;" >
is there any way if i trigger the capture for a post to save in a different name or post name or post id.. so it saves it to the server without replacing the old?如果我触发帖子的捕获以保存在不同的名称或帖子名称或帖子 ID 中,有什么办法可以将其保存到服务器而不替换旧的?
thanks谢谢
Result.php结果.php
Simple change the file name as below:简单更改文件名如下:
$File = "screens/" . time() . ".jpg";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.