~~~
public static function buildExpireImage($data=[],$title=''){
//圖片左上角匯總說明數據,可為空
$table_explain = [
0 => '[日期]'.date('Y-m-d H:i:00'),
1 =>' ',
];
//表頭信息
$table_header = [
"","表頭1","表頭2","表頭3","表頭4","表頭5","表頭6","表頭7","日期","姓名"
];
//每個格子的寬度,可根據數據長度自定義
$field_width = ['60','100','100','130','550','120','120','120','120','120'];
$clo=[];
foreach ($data as $k=>$v){
if($v['expired_date']>=10){
$clo[] = ['x'=>2, 'y'=>$k+2];
}
}
//參數
$params = [
'rowy' => ['1'],
'clo' => $clo,
'row' => count($data), //數據的行數
'file_name' => time().rand(1000000,99999).'test.png', //保存的文件名
'title' => $title,
'table_time' => date("Y-m-d H:i:s"),
'data' => $data,
'table_explain' => $table_explain,
'table_header' => $table_header,
'field_width' => $field_width,
'file_path' => './upload/image/' //文件保存路徑
];
//調用方法
return substr(self::create($params),1);
}
public static function create($params)
{
$base = [
'border' => 10,//圖片外邊框
'file_path' => $params['file_path'],//圖片保存路徑
'title_height' => 25,//報表名稱高度
'title_font_size' => 16,//報表名稱字體大小
'font_ulr' => root_path().'public/simkai.ttf',//字體文件路徑
'text_size' => 12,//正文字體大小
'row_hight' => 30,//每行數據行高
'head_bg_rgb'=>!empty($params['head_bg_rgb'])?$params['head_bg_rgb']:[242,244,42]
];
list($head_red ,$head_green ,$head_blue)=$base['head_bg_rgb'];
$save_path = $base['file_path'] . $params['file_name'];
//如果表說明部分不為空,則增加表圖片的高度
if(!empty($params['table_explain'])){
// $base['title_height'] = $base['title_height'] * count($params['table_explain']);
$base['title_height'] = $base['title_height'] * 2;
}
//計算圖片總寬
$w_sum = $base['border'];
foreach ($params['field_width'] as $key => $value) {
//圖片總寬
$w_sum += $value;
//計算每一列的位置
$base['column_x_arr'][$key] = $w_sum;
}
$base['img_width'] = $w_sum + $base['border'] * 2-$base['border'];//圖片寬度
$base['img_height'] = ($params['row']+1) * $base['row_hight'] + $base['border'] * 2 + $base['title_height'];//圖片高度
$border_top = $base['border'] + $base['title_height'];//表格頂部高度
$border_bottom = $base['img_height'] - $base['border'];//表格底部高度
$img = imagecreatetruecolor($base['img_width'], $base['img_height']);//創建指定尺寸圖片
$bg_color = imagecolorallocate($img, 255,255,255);//設定圖片背景色
$borderbg_color = imagecolorallocate($img, $head_red ,$head_green ,$head_blue);//設定圖片背景色
$text_coler = imagecolorallocate($img, 0, 0, 0);//設定文字顏色
$border_coler = imagecolorallocate($img, 0, 0, 0);//設定邊框顏色
imagefill($img, 0, 0, $bg_color);//填充圖片背景色
//先填充一個黑色的大塊背景
imagefilledrectangle($img, $base['border'], $base['border'] + $base['title_height'], $base['img_width'] - $base['border'], $base['img_height'] - $base['border'], $border_coler);//畫矩形
//再填充一個小兩個像素的 背景色區域,形成一個兩個像素的外邊框
imagefilledrectangle($img, $base['border'] + 2, $base['border'] + $base['title_height'] + 2, $base['img_width'] - $base['border'] - 2, $base['img_height'] - $base['border'] - 2, $bg_color);//畫矩形
foreach($params['rowy'] as $r){
$startx = $base['border'] + 2 ;
$starty = $base['border'] + $base['title_height'] + 2+($r-1)*30;
$endx = $base['img_width'] - $base['border'] - 2;
$endy = $base['border'] + $base['title_height'] + 2 + $r*30;
imagefilledrectangle($img, $startx, $starty, $endx, $endy, $borderbg_color);//畫矩形
}
$diy_border_color = [];
foreach($params['clo'] as $c){
if (!empty($c['rgb']) && !isset($diy_border_color[implode(',', $c['rgb'])])) {
$diy_border_color[implode(',', $c['rgb'])] = imagecolorallocate($img, $c['rgb'][0],$c['rgb'][1],$c['rgb'][2]);//設定圖片背景色
}
$this_border = $borderbg_color;
!empty($c['rgb']) && $this_border = $diy_border_color[implode(',', $c['rgb'])];
$startx = $base['border'] + $base['column_x_arr'][$c['x']-2]-10 ;
$starty = $base['border'] + $base['title_height'] + 2+($c['y']-1)*30;
$endx = $base['border'] + $base['column_x_arr'][$c['x']-1]-10;
$endy = $base['border'] + $base['title_height'] + 2+($c['y'])*30-3;
imagefilledrectangle($img, $startx, $starty, $endx, $endy, $this_border);//畫矩形
}
//畫表格縱線 及 寫入表頭文字
$sum = $base['border'];
foreach($base['column_x_arr'] as $key => $x){
imageline($img, $x, $border_top, $x, $border_bottom,$border_coler);//畫縱線
$this_title_box = imagettfbbox($base['text_size'], 0, $base['font_ulr'], $params['table_header'][$key]);
$title_x_len = $this_title_box[2] - $this_title_box[0];
imagettftext($img, $base['text_size'], 0, $sum + (($x-$sum)/2 - $title_x_len/2), $border_top + ($base['row_hight']+$base['text_size'])/2, $text_coler, $base['font_ulr'], $params['table_header'][$key]);//寫入表頭文字
$sum += $params['field_width'][$key];
}
//畫表格橫線
foreach($params['data'] as $key => $item){
$border_top += $base['row_hight'];
//畫橫線
imageline($img, $base['border'], $border_top, $base['img_width'] - $base['border'], $border_top, $border_coler);
$this_first = imagettfbbox($base['text_size'], 0, $base['font_ulr'], $key);
$first_len = $this_first[2] - $this_first[0];
imagettftext($img, $base['text_size'], 0, $params['field_width'][0]/2 - $first_len/2+$base['border'], $border_top + ($base['row_hight']+$base['text_size'])/2, $text_coler, $base['font_ulr'], $key);//寫入序號
$sub = 0;
$sum = $params['field_width'][0]+$base['border'];
foreach ($item as $value){
$sub++;
$this_title_box = imagettfbbox($base['text_size'], 0, $base['font_ulr'], $value);
$title_x_len = $this_title_box[2] - $this_title_box[0];
imagettftext($img, $base['text_size'], 0, $sum + (($base['column_x_arr'][$sub]-$sum)/2 - $title_x_len/2), $border_top + ($base['row_hight']+$base['text_size'])/2, $text_coler, $base['font_ulr'], $value);//寫入data數據
$sum += $params['field_width'][$sub];
}
}
//計算標題寫入起始位置
$title_fout_box = imagettfbbox($base['title_font_size'], 0, $base['font_ulr'], $params['title']);//imagettfbbox() 返回一個含有 8 個單元的數組表示了文本外框的四個角:
$title_fout_width = $title_fout_box[2] - $title_fout_box[0];//右下角 X 位置 - 左下角 X 位置 為文字寬度
$title_fout_height = $title_fout_box[1] - $title_fout_box[7];//左下角 Y 位置- 左上角 Y 位置 為文字高度
$save_path = $base['file_path'] . $params['file_name'];
if(!is_dir($base['file_path']))//判斷存儲路徑是否存在,不存在則創建
{
mkdir($base['file_path'],0777,true);
}
//居中寫入標題
imagettftext($img, $base['title_font_size'], 0, ($base['img_width'] - $title_fout_width)/2, 20, $text_coler, $base['font_ulr'], $params['title']);
//設置圖片左上角信息
$a_hight = 20;
if(!empty($params['table_explain'])){
foreach ($params['table_explain'] as $key => $value) {
imagettftext($img, $base['text_size'], 0, 10+$a_hight, 50, $text_coler, $base['font_ulr'], $value);
$a_hight += 180;
}
}
imagepng($img,$save_path);//輸出圖片,輸出png使用imagepng方法,輸出gif使用imagegif方法
return $save_path;
}
~~~

- Golang
- Beego框架
- Gin框架
- gin框架介紹
- 使用Gin web框架的知名開源線上項目
- go-admin-gin
- air 熱啟動
- 完整的form表單參數驗證語法
- Go 語言入門練手項目推薦
- Golang是基于多線程模型
- golang 一些概念
- Golang程序開發注意事項
- fatal error: all goroutines are asleep - deadlock
- defer
- Golang 的內建調試器
- go部署
- golang指針重要性
- 包(golang)
- Golang框架選型比較: goframe, beego, iris和gin
- GoFrame
- golang-admin-項目
- go module的使用方法及原理
- go-admin支持多框架的后臺系統(go-admin.cn)
- docker gocv
- go-fac
- MSYS2
- 企業開發框架系統推薦
- gorm
- go-zero
- 優秀系統
- GinSkeleton(gin web 及gin 知識)
- 一次 request -> response 的生命周期概述
- 路由與路由組以及gin源碼學習
- 中間件以及gin源碼學習
- golang項目部署
- 獨立部署golang
- 代理部署golang
- 容器部署golang
- golang交叉編譯
- goravel
- kardianos+gin 項目作為windows服務運行
- go env
- 適用在Windows、Linux和macOS環境下打包Go應用程序的詳細步驟和命令
- Redis
- Dochub
- Docker部署開發go環境
- Docker部署運行go環境
- dochub說明
- Vue
- i18n
- vue3
- vue3基本知識
- element-plus 表格單選
- vue3后臺模板
- Thinkphp
- Casbin權限控制中間件
- 容器、依賴注入、門面、事件、中間件
- tp6問答
- 偽靜態
- thinkphp-queue
- think-throttle
- thinkphp隊列queue的一些使用說明,queue:work和queue:listen的區別
- ThinkPHP6之模型事件的觸發條件
- thinkphp-swoole
- save、update、insert 的區別
- Socket
- workerman
- 介紹
- 從ThinkPHP6移植到Webman的一些技術和經驗(干貨)
- swoole
- swoole介紹
- hyperf
- hf官網
- Swoft
- swoft官網
- easyswoole
- easyswoole官網地址
- EASYSWOOLE 聊天室DEMO
- socket問答
- MySQL
- 聚簇索引與非聚簇索引
- Mysql使用max獲取最大值細節
- 主從復制
- 隨機生成20萬User表的數據
- MySQL進階-----前綴索引、單例與聯合索引
- PHP
- 面向切面編程AOP
- php是單線程的一定程度上也可以看成是“多線程”
- PHP 線程,進程、并發、并行 的理解
- excel數據畫表格圖片
- php第三方包
- monolog/monolog
- league/glide
- 博客-知識網站
- php 常用bc函數
- PHP知識點的應用場景
- AOP(面向切面編程)
- 注解
- 依賴注入
- 事件機制
- phpspreadsheet導出數據和圖片到excel
- Hyperf
- mineAdmin
- 微服務
- nacos注冊服務
- simps-mqtt連接客戶端simps
- Linux
- 切換php版本
- Vim
- Laravel
- RabbitMQ
- thinkphp+rabbitmq
- 博客
- Webman框架
- 框架注意問題
- 關于內存泄漏
- 移動端自動化
- 懶人精靈
- 工具應用
- render
- gitlab Sourcetree
- ssh-agent失敗 錯誤代碼-1
- 資源網站
- Git
- wkhtmltopdf
- MSYS2 介紹
- powershell curl 使用教程
- NSSM(windows服務工具)
- MinGW64
- 知識擴展
- 對象存儲系統
- minio
- 雪花ID
- 請求body參數類型
- GraphQL
- js 深拷貝
- window 共享 centos文件夾
- 前端get/post 請求 特殊符號 “+”傳參數問題
- 什么是SCM系統?SCM系統與ERP系統有什么區別?
- nginx 日志格式統一為 json
- 特殊符號怎么打
- 收藏網址
- 收藏-golang
- 收藏-vue3
- 收藏-php
- 收藏-node
- 收藏-前端
- 規劃ITEM
- 旅游類
- 人臉識別
- dlib
- Docker&&部署
- Docker-compose
- Docker的網絡模式
- rancher
- DHorse
- Elasticsearch
- es與kibana都docke連接
- 4種數據同步到Elasticsearch方案
- GPT
- 推薦系統
- fastposter海報生成
- elasticsearch+logstash+kibana
- beego文檔系統-MinDoc
- jeecg開源平臺
- Java
- 打包部署
- spring boot
- 依賴
- Maven 相關 命令
- Gradle 相關命令
- mybatis
- mybatis.plus
- spring boot 模板引擎
- SpringBoot+Maven多模塊項目(創建、依賴、打包可執行jar包部署測試)完整流程
- Spring Cloud
- Sentinel
- nacos
- Apollo
- java推薦項目
- gradle
- Maven
- Nexus倉庫管理器
- Python
- Masonite框架
- scrapy
- Python2的pip2
- Python3 安裝 pip3
- 安全攻防
- 運維技術
- 騰訊云安全加固建議
- 免費freessl證書申請
- ruby
- homeland
- Protobuf
- GIT
- FFMPEG
- 命令說明
- 音頻
- ffmpeg合并多個MP4視頻
- NODEJS
- 開發npm包
- MongoDB
- php-docker-mongodb環境搭建
- mongo基本命令
- Docker安裝MongoDB最新版并連接
- 少兒編程官網
- UI推薦
- MQTT
- PHP連接mqtt
- EMQX服務端
- php搭建mqtt服務端