|
@@ -27,7 +27,7 @@ class PosterRepository
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 分享帖子生成海报
|
|
|
|
|
|
+ * 分享内容海报
|
|
*/
|
|
*/
|
|
public function post($mainImg,$userInfo,$id,$key)
|
|
public function post($mainImg,$userInfo,$id,$key)
|
|
{
|
|
{
|
|
@@ -141,4 +141,86 @@ class PosterRepository
|
|
|
|
|
|
return jsonSuccess($url);
|
|
return jsonSuccess($url);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 邀请海报
|
|
|
|
+ */
|
|
|
|
+ public function invite($mainImg,$userInfo,$key, $bean)
|
|
|
|
+ {
|
|
|
|
+ $main = ImageManagerStatic::make($mainImg);
|
|
|
|
+
|
|
|
|
+ if(!$userInfo['username']){
|
|
|
|
+ $userInfo['username'] = '';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 彩虹豆数
|
|
|
|
+ $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');
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 用户名称
|
|
|
|
+ $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('https://www.jianshu.com/p/1c78294f26f8'));
|
|
|
|
+
|
|
|
|
+ $qrcode->resize(170,170);
|
|
|
|
+
|
|
|
|
+ $main->insert($qrcode,'top-left', 547, 944);
|
|
|
|
+
|
|
|
|
+ // 存储图片
|
|
|
|
+ $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);
|
|
|
|
+ }
|
|
}
|
|
}
|