|
@@ -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);
|
|
@@ -38,14 +37,17 @@ class PosterRepository
|
|
return jsonError('获取内容信息失败');
|
|
return jsonError('获取内容信息失败');
|
|
}
|
|
}
|
|
|
|
|
|
- // 设置头像
|
|
|
|
- if(!$userInfo['avatar']){
|
|
|
|
- $userInfo['avatar'] = 'https://wx.qlogo.cn/mmopen/vi_32/DYAIOgq83ep3asJn8emiat1MnPdviaPNroWY3f65y5ezkTAk2qtibv7ea9Ht9R2ahxr9bicY1DIj5vN5FibpDOwXegg/132';
|
|
|
|
- }
|
|
|
|
|
|
+ // 彩虹豆数
|
|
|
|
+ $bean = config('customer.share_post_bean');
|
|
|
|
+ $beanWidth = 540;
|
|
|
|
+ if(strlen($bean) == 4) $beanWidth = 532;
|
|
|
|
+ $main->text($bean, $beanWidth, 1214, function ($font) {
|
|
|
|
+ $font->file(public_path('font/PingFang Bold.ttf'));
|
|
|
|
+ $font->size(28);
|
|
|
|
+ $font->color('#FFFFFF');
|
|
|
|
+ $font->align('left');
|
|
|
|
+ });
|
|
|
|
|
|
- if(!$userInfo['username']){
|
|
|
|
- $userInfo['username'] = '我是谁啦啦啦里哦';
|
|
|
|
- }
|
|
|
|
//内容图片
|
|
//内容图片
|
|
$postImg = ImageManagerStatic::make($postDetail['img'].'!poster_app')->fit(750, 962);
|
|
$postImg = ImageManagerStatic::make($postDetail['img'].'!poster_app')->fit(750, 962);
|
|
$main->insert($postImg, 'left-top', 0, 0);
|
|
$main->insert($postImg, 'left-top', 0, 0);
|
|
@@ -100,45 +102,130 @@ class PosterRepository
|
|
});
|
|
});
|
|
|
|
|
|
// 用户名称
|
|
// 用户名称
|
|
- $main->text($userInfo['username'], 155, 470, function ($font) {
|
|
|
|
- $font->file(public_path('font/PingFang Regular.ttf'));
|
|
|
|
- $font->size(24);
|
|
|
|
- $font->color('#FFFFFF');
|
|
|
|
- $font->align('left');
|
|
|
|
- });
|
|
|
|
|
|
+ if($userInfo['username']){
|
|
|
|
+ $main->text($userInfo['username'], 155, 470, function ($font) {
|
|
|
|
+ $font->file(public_path('font/PingFang Regular.ttf'));
|
|
|
|
+ $font->size(24);
|
|
|
|
+ $font->color('#FFFFFF');
|
|
|
|
+ $font->align('left');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
|
|
- //用户头像
|
|
|
|
- $avatar = Image::make($userInfo['avatar'])->resize(42,42);
|
|
|
|
- $new= Image::canvas(750, 1334);
|
|
|
|
- $r=$avatar->width() /2;
|
|
|
|
- for($x=0;$x<$avatar->width();$x++) {
|
|
|
|
|
|
+ // 用户头像
|
|
|
|
+ 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++) {
|
|
|
|
|
|
- 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(config('customer.share_post_h5url')."?post_id={$id}&invite_code={$userInfo['invite_code']}"));
|
|
|
|
|
|
$qrcode->resize(164,164);
|
|
$qrcode->resize(164,164);
|
|
|
|
|
|
$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';
|
|
|
|
+ Storage::put($filename, (string)$main->encode('jpg'));
|
|
|
|
+ $url = 'http://oss.caihongxingqiu.net/'.$filename;
|
|
|
|
+ Redis::set($key, $url);
|
|
|
|
+ Redis::expire($key, 3600 * 24 * 3);
|
|
|
|
+
|
|
|
|
+ return jsonSuccess($url);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 邀请海报
|
|
|
|
+ */
|
|
|
|
+ public function invite($mainImg,$userInfo,$key, $bean)
|
|
|
|
+ {
|
|
|
|
+ $main = ImageManagerStatic::make($mainImg);
|
|
|
|
+
|
|
|
|
+ // 彩虹豆数
|
|
|
|
+ $beanWidth = 194;
|
|
|
|
+ if(strlen($bean) == 4) $beanWidth = 182;
|
|
|
|
+ $main->text($bean, $beanWidth, 1060, function ($font) {
|
|
|
|
+ $font->file(public_path('font/PingFang Bold.ttf'));
|
|
|
|
+ $font->size(36);
|
|
|
|
+ $font->color('#C74A48');
|
|
|
|
+ $font->align('left');
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // 邀请码
|
|
|
|
+ if($userInfo['invite_code']){
|
|
|
|
+ $str = $userInfo['invite_code'];
|
|
|
|
+ $strLower = strtolower($str);
|
|
|
|
+ $upperNumber = 0;
|
|
|
|
+ for($i=0;$i<6;$i++){
|
|
|
|
+ if($str[$i] != $strLower[$i]) $upperNumber++;
|
|
|
|
+ }
|
|
|
|
+ $codeWidth = 212 - $upperNumber * 3;
|
|
|
|
+ $main->text($str, $codeWidth, 912, function ($font) {
|
|
|
|
+ $font->file(public_path('font/PingFang Regular.ttf'));
|
|
|
|
+ $font->size(28);
|
|
|
|
+ $font->color('#3C5852');
|
|
|
|
+ $font->align('left');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 用户名称
|
|
|
|
+ if($userInfo['username']){
|
|
|
|
+ $main->text($userInfo['username'], 30, 860, function ($font) {
|
|
|
|
+ $font->file(public_path('font/PingFang Regular.ttf'));
|
|
|
|
+ $font->size(28);
|
|
|
|
+ $font->color('#3C5852');
|
|
|
|
+ $font->align('left');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 用户头像
|
|
|
|
+ if($userInfo['avatar']){
|
|
|
|
+ $avatar = Image::make($userInfo['avatar'])->resize(88,88);
|
|
|
|
+ $new= Image::canvas(750, 1346);
|
|
|
|
+ $r=$avatar->width() /2;
|
|
|
|
+ for($x=0;$x<$avatar->width();$x++) {
|
|
|
|
+
|
|
|
|
+ for($y=0;$y<$avatar->height();$y++) {
|
|
|
|
+
|
|
|
|
+ $c=$avatar->pickColor($x,$y,'array');
|
|
|
|
+
|
|
|
|
+ if(((($x-$r) * ($x-$r) + ($y-$r) * ($y-$r)) < ($r*$r))) {
|
|
|
|
+ $new->pixel($c,$x,$y);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $main->insert($new, 'top-left', 30, 717);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $qrcode = Image::make(QrCode::format('png')->generate(config('customer.share_invite_h5url')."?invite_code={$userInfo['invite_code']}"));
|
|
|
|
+
|
|
|
|
+ $qrcode->resize(170,170);
|
|
|
|
+
|
|
|
|
+ $main->insert($qrcode,'top-left', 547, 944);
|
|
|
|
|
|
// 存储图片
|
|
// 存储图片
|
|
$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);
|
|
}
|
|
}
|
|
}
|
|
}
|