根据您的要求,您可以在点击启动电子邮件的事件时调用js。
你可以用
HTML to Canvas
你只需要包括JS
https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js
进入你的html。
然后你可以使用下面的脚本
html2canvas(jQuery(".main-content"), {
useCORS: true,
onrendered: function(canvas) {
theCanvas = canvas;
document.body.appendChild(canvas);
dataOverview = canvas.toDataURL('image/png');
uploadImage(dataOverview);//this is custom build function
}});
.main内容是要转换为图像的节的选择器
function uploadImage(dataOverview)
{
if(dataOverview)
{
jQuery.ajax({
url: 'ajax url to post image data',
type : 'POST',
data : {
dataOverview: dataOverview,
},
dataType : 'JSON',
success: function(response)
{
if(response.code == 200)
{
//perform your action on success
}
}
});
}
}
$dataOverview = $_POST['dataOverview'];
$dataOverviewData=substr($dataOverview, strpos($dataOverview, ",")+1);
$dataOverviewunencodedData=base64_decode($dataOverviewData);
$rand = rand();
$dataOverViewfname_png = $rand.'.png';
$dataOverimgfile_png='path to the directory where you want to save the image';
$imagegerated=file_put_contents($dataOverimgfile_png, $dataOverviewunencodedData);
这将生成您在选择器中传递的html元素的png图像。
这是一个工作代码,因为我已经在我的一些项目中使用它。
或者如果你想把原始的html转换成图像,你可以使用下面的代码
<?php
require 'pdfcrowd.php';
try
{
// create the API client instance
$client = new \Pdfcrowd\HtmlToImageClient("your_username", "your_apikey");
// configure the conversion
$client->setOutputFormat("png");
// run the conversion and write the result to a file
$client->convertFileToFile("/path/to/MyLayout.html", "MyLayout.png");
}
catch(\Pdfcrowd\Error $why)
{
// report the error
error_log("Pdfcrowd Error: {$why}\n");
// handle the exception here or rethrow and handle it at a higher level
throw $why;
}
?>
PDFCROWD