123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2019/6/20
- * Time: 16:50
- */
- namespace App\Repositories;
- use Faker\Provider\Image;
- use Intervention\Image\ImageManagerStatic;
- use Illuminate\Support\Facades\Storage;
- class PosterRepository
- {
- public $main;
- public function __construct($mainImg)
- {
- if (extension_loaded('imagick')) {
- ImageManagerStatic::configure(['driver'=>'imagick']);
- }
- $this->main = ImageManagerStatic::make($mainImg);
- return $this->main->encoded;
- }
- /**
- * 分享帖子生成海报
- */
- public function post($userInfo, $id)
- {
- // return $this->main->response();
- // 设置头像
- if(!$userInfo['avatar']){
- $userInfo['avatar'] = 'https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83ep3asJn8emiat1MnPdviaPNroWY3f65y5ezkTAk2qtibv7ea9Ht9R2ahxr9bicY1DIj5vN5FibpDOwXegg/132';
- }
- $avatarurl = ImageManagerStatic::make($userInfo['avatar'])->fit(80, 80);
- $image = $this->main->insert($avatarurl, 'left-top', 40, 309*2);
- $path = '/public/post'.$id.'.png';
- $image->save($path);
- //$url = config('filesystems.disks.oss.uri').$path;
- // 存储图片
- $url = Storage::put($path, $image->basePath());
- return $url;
- }
- }
|