|
@@ -170,9 +170,10 @@ trait Fill
|
|
|
* 图片增加logo
|
|
|
* @param resource $im 图片资源
|
|
|
* @param resource $logo logo图
|
|
|
+ * @param int $stroke 是否对logo进行描边
|
|
|
* @return resource
|
|
|
*/
|
|
|
- public function imageAddLogo($im, $logo) {
|
|
|
+ public function imageAddLogo($im, $logo, $stroke = 1) {
|
|
|
//加载logo
|
|
|
$ext = pathinfo($logo, PATHINFO_EXTENSION);
|
|
|
|
|
@@ -193,7 +194,7 @@ trait Fill
|
|
|
throw new \Exception('Unsupported image format');
|
|
|
break;
|
|
|
}
|
|
|
- return $this->imageAddLogoRes($im, $logoRes);
|
|
|
+ return $this->imageAddLogoRes($im, $logoRes, $stroke);
|
|
|
}
|
|
|
/**
|
|
|
* 通过图片资源生成
|
|
@@ -201,53 +202,53 @@ trait Fill
|
|
|
* @param resource $logoRes Logo资源
|
|
|
* @return resource
|
|
|
*/
|
|
|
- public function imageAddLogoRes($im, $logoRes) {
|
|
|
+ public function imageAddLogoRes($im, $logoRes, $stroke = 0) {
|
|
|
//计算宽和高
|
|
|
$w = imagesx($im);
|
|
|
$h = imagesy($im);
|
|
|
$logoRes = $this->resizeImage($logoRes, min(36, $w / 5), min(36, $h / 5));
|
|
|
$srcWidth = imagesx($logoRes);
|
|
|
$srcHeight = imagesy($logoRes);
|
|
|
-
|
|
|
-
|
|
|
- //logo边框1 小
|
|
|
- $bor1 = ImageCreate($srcWidth + 2, $srcHeight + 2);
|
|
|
- ImageColorAllocate($bor1, 237, 234, 237);//背景色
|
|
|
- $bor1Width = imagesx($bor1);
|
|
|
- $bor1Height = imagesy($bor1);
|
|
|
-
|
|
|
- //logo边框2 中
|
|
|
- $bor2 = ImageCreate($bor1Width + 8, $bor1Height + 8);
|
|
|
- ImageColorAllocate($bor2, 255, 255, 255);//背景色
|
|
|
- $bor2_w = imagesx($bor2);
|
|
|
- $bor2_h = imagesy($bor2);
|
|
|
-
|
|
|
- //logo边框3 大
|
|
|
- $bor3 = ImageCreate($bor2_w + 2, $bor2_h + 2);
|
|
|
- ImageColorAllocate($bor3, 215, 215, 215);//背景色
|
|
|
- $bor3Width = imagesx($bor3);
|
|
|
- $bor3Height = imagesy($bor3);
|
|
|
-
|
|
|
- //圆角处理
|
|
|
- $rounder = new \QrCode\RoundedCorner('', 5);
|
|
|
-
|
|
|
- //二维码与logo边框3合并
|
|
|
- $bor3 = $rounder->round_it($bor3);
|
|
|
- imagecopymerge($im, $bor3, ($w / 2) - ($bor3Width / 2), ($h / 2) - ($bor3Height / 2), 0, 0, $bor3Width, $bor3Height, 100);
|
|
|
- imagedestroy($bor3);
|
|
|
-
|
|
|
- //二维码与logo边框2合并
|
|
|
- $bor2 = $rounder->round_it($bor2);
|
|
|
- imagecopymerge($im, $bor2, ($w / 2) - ($bor2_w / 2), ($h / 2) - ($bor2_h / 2), 0, 0, $bor2_w, $bor2_h, 100);
|
|
|
- imagedestroy($bor2);
|
|
|
-
|
|
|
- //二维码与logo边框1合并
|
|
|
- $bor1 = $rounder->round_it($bor1);
|
|
|
- imagecopymerge($im, $bor1, ($w / 2) - ($bor1Width / 2), ($h / 2) - ($bor1Height / 2), 0, 0, $bor1Width, $bor1Height, 100);
|
|
|
- imagedestroy($bor1);
|
|
|
-
|
|
|
- //二维码与logo合并
|
|
|
- $logoRes = $rounder->round_it($logoRes);
|
|
|
+ if($stroke) {
|
|
|
+ //logo边框1 小
|
|
|
+ $bor1 = ImageCreate($srcWidth + 2, $srcHeight + 2);
|
|
|
+ ImageColorAllocate($bor1, 237, 234, 237);//背景色
|
|
|
+ $bor1Width = imagesx($bor1);
|
|
|
+ $bor1Height = imagesy($bor1);
|
|
|
+
|
|
|
+ //logo边框2 中
|
|
|
+ $bor2 = ImageCreate($bor1Width + 8, $bor1Height + 8);
|
|
|
+ ImageColorAllocate($bor2, 255, 255, 255);//背景色
|
|
|
+ $bor2_w = imagesx($bor2);
|
|
|
+ $bor2_h = imagesy($bor2);
|
|
|
+
|
|
|
+ //logo边框3 大
|
|
|
+ $bor3 = ImageCreate($bor2_w + 2, $bor2_h + 2);
|
|
|
+ ImageColorAllocate($bor3, 215, 215, 215);//背景色
|
|
|
+ $bor3Width = imagesx($bor3);
|
|
|
+ $bor3Height = imagesy($bor3);
|
|
|
+
|
|
|
+ //圆角处理
|
|
|
+ $rounder = new \QrCode\RoundedCorner('', 5);
|
|
|
+
|
|
|
+ //二维码与logo边框3合并
|
|
|
+ $bor3 = $rounder->round_it($bor3);
|
|
|
+ imagecopymerge($im, $bor3, ($w / 2) - ($bor3Width / 2), ($h / 2) - ($bor3Height / 2), 0, 0, $bor3Width, $bor3Height, 100);
|
|
|
+ imagedestroy($bor3);
|
|
|
+
|
|
|
+ //二维码与logo边框2合并
|
|
|
+ $bor2 = $rounder->round_it($bor2);
|
|
|
+ imagecopymerge($im, $bor2, ($w / 2) - ($bor2_w / 2), ($h / 2) - ($bor2_h / 2), 0, 0, $bor2_w, $bor2_h, 100);
|
|
|
+ imagedestroy($bor2);
|
|
|
+
|
|
|
+ //二维码与logo边框1合并
|
|
|
+ $bor1 = $rounder->round_it($bor1);
|
|
|
+ imagecopymerge($im, $bor1, ($w / 2) - ($bor1Width / 2), ($h / 2) - ($bor1Height / 2), 0, 0, $bor1Width, $bor1Height, 100);
|
|
|
+ imagedestroy($bor1);
|
|
|
+
|
|
|
+ //二维码与logo合并
|
|
|
+ $logoRes = $rounder->round_it($logoRes);
|
|
|
+ }
|
|
|
imagecopymerge($im, $logoRes, ($w / 2) - ($srcWidth / 2), ($h / 2) - ($srcHeight / 2), 0, 0, $srcWidth, $srcHeight, 100);
|
|
|
imagedestroy($logoRes);
|
|
|
return $im;
|