安装 intervention/image
扩展包
composer require intervention/image
在 config/app.php
中加入
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
| .....
'providers' => [
....
Intervention\Image\ImageServiceProvider::class
]
'aliases' => [
....
'Image' => Intervention\Image\Facades\Image::class
]
.....
|
至此,插件安装成功。开始上代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| $fileSize = getimagesize($file); $fontSize = $fileSize[1]/25; $bevel = hypot($fileSize[0],$fileSize[1]); $img = Image::make($file);
for ($i=0;$i<intval($bevel/($fontSize*5));$i++){ for ($j=0;$j<intval($bevel/($fontSize*8));$j++){ $img->text('证件仅供展示使用', $j*($fontSize*8), $i*($fontSize*5),function ($font)use($fontSize){ $font->file(public_path('font/FZFSJW.TTF')); $font->size($fontSize); $font->angle(45); $font->color('#f40'); }); } }
|