|
@@ -8,6 +8,7 @@
|
|
namespace App\Repositories;
|
|
namespace App\Repositories;
|
|
|
|
|
|
use App\Traits\CommunityTrait;
|
|
use App\Traits\CommunityTrait;
|
|
|
|
+use Illuminate\Support\Facades\Redis;
|
|
use Intervention\Image\Facades\Image;
|
|
use Intervention\Image\Facades\Image;
|
|
use Intervention\Image\ImageManagerStatic;
|
|
use Intervention\Image\ImageManagerStatic;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\Storage;
|
|
@@ -23,14 +24,12 @@ class PosterRepository
|
|
if (extension_loaded('imagick')) {
|
|
if (extension_loaded('imagick')) {
|
|
ImageManagerStatic::configure(['driver'=>'imagick']);
|
|
ImageManagerStatic::configure(['driver'=>'imagick']);
|
|
}
|
|
}
|
|
-// $this->main = ImageManagerStatic::make($mainImg);
|
|
|
|
-// return $this->main->encoded;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* 分享帖子生成海报
|
|
* 分享帖子生成海报
|
|
*/
|
|
*/
|
|
- public function post($mainImg,$userInfo, $id)
|
|
|
|
|
|
+ public function post($mainImg,$userInfo,$id,$key)
|
|
{
|
|
{
|
|
$main = ImageManagerStatic::make($mainImg);
|
|
$main = ImageManagerStatic::make($mainImg);
|
|
$postDetail = $this->getPostDetail($id);
|
|
$postDetail = $this->getPostDetail($id);
|
|
@@ -44,7 +43,7 @@ class PosterRepository
|
|
}
|
|
}
|
|
|
|
|
|
if(!$userInfo['username']){
|
|
if(!$userInfo['username']){
|
|
- $userInfo['username'] = '我是谁啦啦啦里哦';
|
|
|
|
|
|
+ $userInfo['username'] = '';
|
|
}
|
|
}
|
|
//内容图片
|
|
//内容图片
|
|
$postImg = ImageManagerStatic::make($postDetail['img'].'!poster_app')->fit(750, 962);
|
|
$postImg = ImageManagerStatic::make($postDetail['img'].'!poster_app')->fit(750, 962);
|
|
@@ -106,25 +105,26 @@ class PosterRepository
|
|
$font->color('#FFFFFF');
|
|
$font->color('#FFFFFF');
|
|
$font->align('left');
|
|
$font->align('left');
|
|
});
|
|
});
|
|
|
|
+ // 用户头像
|
|
|
|
+ if($userInfo['avatar']){
|
|
|
|
+ $avatar = Image::make($userInfo['avatar'])->resize(42,42);
|
|
|
|
+ $new= Image::canvas(750, 1334);
|
|
|
|
+ $r=$avatar->width() /2;
|
|
|
|
+ for($x=0;$x<$avatar->width();$x++) {
|
|
|
|
|
|
- //用户头像
|
|
|
|
- $avatar = Image::make($userInfo['avatar'])->resize(42,42);
|
|
|
|
- $new= Image::canvas(750, 1334);
|
|
|
|
- $r=$avatar->width() /2;
|
|
|
|
- for($x=0;$x<$avatar->width();$x++) {
|
|
|
|
|
|
+ for($y=0;$y<$avatar->height();$y++) {
|
|
|
|
|
|
- for($y=0;$y<$avatar->height();$y++) {
|
|
|
|
|
|
+ $c=$avatar->pickColor($x,$y,'array');
|
|
|
|
|
|
- $c=$avatar->pickColor($x,$y,'array');
|
|
|
|
|
|
+ if(((($x-$r) * ($x-$r) + ($y-$r) * ($y-$r)) < ($r*$r))) {
|
|
|
|
+ $new->pixel($c,$x,$y);
|
|
|
|
+ }
|
|
|
|
|
|
- if(((($x-$r) * ($x-$r) + ($y-$r) * ($y-$r)) < ($r*$r))) {
|
|
|
|
- $new->pixel($c,$x,$y);
|
|
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
- $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 = Image::make(QrCode::format('png')->generate('https://www.jianshu.com/p/1c78294f26f8'));
|
|
|
|
|
|
@@ -132,13 +132,13 @@ class PosterRepository
|
|
|
|
|
|
$main->insert($qrcode,'top-left', 63, 1087);
|
|
$main->insert($qrcode,'top-left', 63, 1087);
|
|
|
|
|
|
-// $main->save(public_path('test/post_id'.$id.'.png'));
|
|
|
|
-// return $response = $main->response();
|
|
|
|
-
|
|
|
|
// 存储图片
|
|
// 存储图片
|
|
$filename = date('Ym').'/'.time() . '_' . uniqid() . '.jpg';
|
|
$filename = date('Ym').'/'.time() . '_' . uniqid() . '.jpg';
|
|
- $url = Storage::put($filename, (string)$main->encode('jpg'));
|
|
|
|
|
|
+ Storage::put($filename, (string)$main->encode('jpg'));
|
|
|
|
+ $url = 'http://oss.caihongxingqiu.net/'.$filename;
|
|
|
|
+ Redis::set($key, $url);
|
|
|
|
+ Redis::expire($key, 3600 * 24 * 3);
|
|
|
|
|
|
- return $filename;
|
|
|
|
|
|
+ return jsonSuccess($url);
|
|
}
|
|
}
|
|
}
|
|
}
|