|
@@ -16,22 +16,23 @@ use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
|
|
class PosterRepository
|
|
|
{
|
|
|
use CommunityTrait;
|
|
|
- public $main;
|
|
|
+ public $main;
|
|
|
|
|
|
public function __construct($mainImg)
|
|
|
{
|
|
|
if (extension_loaded('imagick')) {
|
|
|
ImageManagerStatic::configure(['driver'=>'imagick']);
|
|
|
}
|
|
|
- $this->main = ImageManagerStatic::make($mainImg);
|
|
|
- return $this->main->encoded;
|
|
|
+// $this->main = ImageManagerStatic::make($mainImg);
|
|
|
+// return $this->main->encoded;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 分享帖子生成海报
|
|
|
*/
|
|
|
- public function post($userInfo, $id)
|
|
|
+ public function post($mainImg,$userInfo, $id)
|
|
|
{
|
|
|
+ $main = ImageManagerStatic::make($mainImg);
|
|
|
$postDetail = $this->getPostDetail($id);
|
|
|
if(!$postDetail){
|
|
|
return jsonError('获取内容信息失败');
|
|
@@ -47,19 +48,19 @@ class PosterRepository
|
|
|
}
|
|
|
//内容图片
|
|
|
$postImg = ImageManagerStatic::make($postDetail['img'].'!poster_app')->fit(750, 962);
|
|
|
- $this->main->insert($postImg, 'left-top', 0, 0);
|
|
|
+ $main->insert($postImg, 'left-top', 0, 0);
|
|
|
|
|
|
//遮罩
|
|
|
$mask = ImageManagerStatic::make(public_path('/image/post/mask.png'))->fit(750, 962);
|
|
|
- $this->main->insert($mask, 'left-top', 0, 0);
|
|
|
+ $main->insert($mask, 'left-top', 0, 0);
|
|
|
|
|
|
//logo
|
|
|
$mask = ImageManagerStatic::make(public_path('/image/post/logo.png'))->fit(145, 38);
|
|
|
- $this->main->insert($mask, 'left-top', 55, 60);
|
|
|
+ $main->insert($mask, 'left-top', 55, 60);
|
|
|
|
|
|
//话题
|
|
|
if(isset($postDetail['topic'][0]['name'])){
|
|
|
- $this->main->text('#'.$postDetail['topic'][0]['name'].'#', 55, 240, function ($font) {
|
|
|
+ $main->text('#'.$postDetail['topic'][0]['name'].'#', 55, 240, function ($font) {
|
|
|
$font->file(public_path('font/PingFang Regular.ttf'));
|
|
|
$font->size(26);
|
|
|
$font->color('#FFFFFF');
|
|
@@ -83,7 +84,7 @@ class PosterRepository
|
|
|
}else{
|
|
|
$height = 350;
|
|
|
}
|
|
|
- $this->main->text($title, 55, $height, function ($font) {
|
|
|
+ $main->text($title, 55, $height, function ($font) {
|
|
|
$font->file(public_path('font/PingFang Medium.ttf'));
|
|
|
$font->size(36);
|
|
|
$font->color('#FFFFFF');
|
|
@@ -91,7 +92,7 @@ class PosterRepository
|
|
|
});
|
|
|
|
|
|
// ——
|
|
|
- $this->main->text('——', 55, 456, function ($font) {
|
|
|
+ $main->text('——', 55, 456, function ($font) {
|
|
|
$font->file(public_path('font/PingFang Regular.ttf'));
|
|
|
$font->size(20);
|
|
|
$font->color('#FFFFFF');
|
|
@@ -99,7 +100,7 @@ class PosterRepository
|
|
|
});
|
|
|
|
|
|
// 用户名称
|
|
|
- $this->main->text($userInfo['username'], 155, 470, function ($font) {
|
|
|
+ $main->text($userInfo['username'], 155, 470, function ($font) {
|
|
|
$font->file(public_path('font/PingFang Regular.ttf'));
|
|
|
$font->size(24);
|
|
|
$font->color('#FFFFFF');
|
|
@@ -123,21 +124,21 @@ class PosterRepository
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- $this->main->insert($new, 'top-left', 105, 436);
|
|
|
+ $main->insert($new, 'top-left', 105, 436);
|
|
|
|
|
|
$qrcode = Image::make(QrCode::format('png')->generate('https://www.jianshu.com/p/1c78294f26f8'));
|
|
|
|
|
|
$qrcode->resize(164,164);
|
|
|
|
|
|
- $this->main->insert($qrcode,'top-left', 63, 1087);
|
|
|
+ $main->insert($qrcode,'top-left', 63, 1087);
|
|
|
|
|
|
- $path = '/public/post'.$id.'.png';
|
|
|
-// $image->save($path);
|
|
|
- //$url = config('filesystems.disks.oss.uri').$path;
|
|
|
+// $main->save(public_path('test/post_id'.$id.'.png'));
|
|
|
+// return $response = $main->response();
|
|
|
|
|
|
// 存储图片
|
|
|
-// $url = Storage::put($path, $image->basePath());
|
|
|
+ $filename = date('Ym').'/'.time() . '_' . uniqid() . '.jpg';
|
|
|
+ $url = Storage::put($filename, (string)$main->encode('jpg'));
|
|
|
|
|
|
- return $this->main->response('png');
|
|
|
+ return $filename;
|
|
|
}
|
|
|
}
|