小编给大家分享一下TP5.1如何生成海报,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
//远程下载图片
function downImg($imgUrl, $savePath = '',$filename = '')
{
if(!isDirFile($savePath)){
mkdir($savePath,0777,true);
}
if($savePath == ''){
return false;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $imgUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);//这个是重点。
$file = curl_exec($ch);
curl_close($ch);
$ext = pathinfo($imgUrl,PATHINFO_EXTENSION);
if(!$ext)
$ext = 'png';
$resource = fopen($savePath . $filename . '.' .$ext, 'w');
$res = fwrite($resource, $file);
fclose($resource);
if($res){
return $filename . '.' .$ext;
}else{
return false;
}
}
//生成缩略图
function imgToThumb($imgUrl){
$image = \think\Image::open($imgUrl);
$image->thumb(104, 104)->radius(50)->save($imgUrl);
}
//判断文件或者目录是否存在
function isDirFile($path,$isfile = false){
if($isfile){
return file_exists($path) ? true : false;
}else{
return is_dir($path) ? true : false;
}
}
//水印
function water($codefile,$text,$newFile,$waterBg="./uploads/haibao.jpg"){
//判断图片尺寸-生成缩略图
list($width, $height, $type, $attr) = getimagesize($codefile);
if($width > 104 || $height > 104){
imgToThumb($codefile);
}
if(!isDirFile(\Env::get('root_path').'public/'.$waterBg,true)){
return false;
}
$image = \think\Image::open($waterBg);
/*
if($strlen>8){
$text = mb_substr($text,0,8,'UTF-8').'...';
$offset = [380,985];
}
*/
$textName = isset($text[0]) ? $text[0] : '';
$textData = isset($text[1]) ? $text[1] : '';
$textDays = isset($text[2]) ? $text[2] : '';
$textNums = isset($text[3]) ? $text[3] : '';
$image->text($textName,\Env::get('root_path').'public/static/font/msyh.ttf',24,'#323232',[150,822])
->text($textData,\Env::get('root_path').'public/static/font/msyh.ttf',14,'#c5a98f',[150,864])
->text($textDays,\Env::get('root_path').'public/static/font/msyh.ttf',46,'#9e7758',[360,810])
->text($textNums,\Env::get('root_path').'public/static/font/msyh.ttf',46,'#9e7758',[540,810])
->water($codefile,[36,804])->save($newFile);
return $newFile;
}
以上是“TP5.1如何生成海报”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。
原文链接:https://my.oschina.net/u/914487/blog/3079087