https://book.employleague.cn/
package topthink/think-image
composer require topthink/think-image
Thinkphp5.0 ~ thinkphp6.0都可以用
使用方式
打开图片
use think/Image;
...
$handler = Image::open($path); // $path 本地图片路径
打开网络图片
private function download_remote_pic($url){
$header = [
'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding: gzip, deflate',
];
$curl = curl_init();
curl_setopt($curl,CURLOPT_RETURNTRANSFER,true);
curl_setopt($curl,CURLOPT_HEADER,0);
curl_setopt($curl,CURLOPT_NOBODY,0);
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl,CURLOPT_URL,$url);
$output= curl_exec($curl);
curl_close($curl);
return $output;
}
$imageFile = $this->download_remote_pic('https://微信头像地址');
file_put_content($path, $imageFile); // $path 图片路径
$handler = Image::open($path);
图片合成
$local = [100, 100];
$handler->water($path, $local); // $path 图片本地路径 $local 数组 [$x, $y];
文字添加
$handler->text($txt, $font, $size, $color, $local);
'$txt 是需要添加的文字 $font 字体文件 中文建议将C盘windows/Font下的楷体文件移动到项目目录下引用'
'$size number类型 字体大小 单位px $color 颜色 $local 同图片一样可以传入图片'
图片保存
$handler->save($path); //$path文件路径