冰豆网

分享网络精彩
bingdou.com.cn

php快照网页

时间:2020-08-20加入收藏

第一步:在远程连接好之后,在窗口命令输入:

yum install -y https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox-0.12.5-1.centos7.x86_64.rpm

第二步:创建一个xxxxx.PHP的文件,输入以下代码(本地创建一个img的文件夹)

<?php
function allow_domain($url){
    $is_allow=false;
    //获取不带端口号的域名前缀
    $servername=trim($_SERVER['SERVER_NAME']);
    //授权域名列表
    $Array=array("您的域名");
    //遍历数组
    foreach($Array as $value){
        $value=trim($value);
        $domain=explode($value,$servername);
        if(count($domain)>1){
            $is_allow=true;
            break;
        }
    }
    if(!$is_allow){
        die("域名未授权!");    //授权失败
    }else{
        //echo "域名已授权!";    //授权成功
        Generatepictures($url);
    }
}
function Generatepictures($url){
$url= str_replace("http://","",$url);
$url= str_replace("https://","",$url);
$file = getcwd().'/img/'.$url.'.jpg';
if(!is_file($file))
{
set_time_limit(0);
shell_exec('wkhtmltoimage  --crop-w 1080 --crop-h 700 --quality 15 '.$url.' '.getcwd().'/img/'.$url.'.jpg');
}
$filename="/img/".$url.".jpg";
//  echo $filename;
header('Content-type:image/png');
header("Cache-Control:max-age=600000");
echo file_get_contents(getcwd().'/img/'.$url.'.jpg');
}
if (isset($_GET['url']))  
    {
       allow_domain($_GET['url']);
    }
?>

第三步:在宝塔面板PHP里面管理-禁用函数-删除shell_exec 即可
第四步:上传字体
原因:缺少中文字体
解决方法:
网络上下载宋体(simsun.ttc)文件
上传到服务器的 /usr/share/fonts/chinese/TrueType/ 文件夹中(没有这些文件夹新建即可)
第五步:链接代码:http://您的域名/xxxxx.php?url=www.bingdou.net调用快照的网址

字体附件:https://t00y.com/file/1675875-458250141

打 赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

TGA: php 技巧

分享到:


官方微信二维码冰豆网官方微信公众号