將HTML頁面截取成圖片保存??注意:引入jquery.js插件
后臺保存
php處理圖片代碼
public function ajax_crop_img($gid)
{
????????$contents = $_POST['contents'];
????????$oss = model('common/oss', 'logic');
????????$base64_body = substr(strstr($contents,','),1);
????????//將產(chǎn)品名片上傳至阿里云
????????$return = $oss->save($base64_body,'card','.png');
????????$res_qrcode = model('product/ProductGoods')->where(['gid'=>$gid])->value('res_qrcode');
????????if($return['code'] == 200){
????????if($res_qrcode==''){
????????????????//二維碼生成成功闻书,寫入對應(yīng)的產(chǎn)品信息
????????????????????model('product/ProductGoods')->where(['gid'=>$gid])->setField('res_qrcode',$return['url']);
????}
????????echo json_encode(["code"=>200,"message"=>"success","data"=>['imgUrl'=>$return['url']]]);
}
}
HTML頁面js代碼
var gid = {$goodsInfo['gid']}; html2canvas(document.querySelector("#capture")).then(canvas => { $.post("https://three.api.skinrun.me/web/index/ajax_crop_img", { name: "John",gid:gid ,contents: canvas.toDataURL() } ); });?
注意:將要截取的部分的跟標(biāo)簽加上id="capture"