yeshihao 1 год назад
Родитель
Сommit
cf2faeb841

+ 6 - 3
dyu/application/common/service/watermark/WaterMarkBase.php

@@ -28,6 +28,8 @@ class WaterMarkBase
 
 	public $water;
 
+	public $water2;
+
 	public $wxapp_id;
 
 	public $type;
@@ -41,10 +43,11 @@ class WaterMarkBase
 	 * @param $water //水印内容
 	 * @param $wxapp_id //wxappid
 	 */
-	public function __construct($url, $water, $wxapp_id, $type = 'image')
+	public function __construct($url, $water, $wxapp_id, $type = 'image', $water2 = '')
 	{
 		$this->url      = $url;
 		$this->water    = $water;
+		$this->water2   = $water2;
 		$this->wxapp_id = $wxapp_id;
 		$this->type     = $type;
 	}
@@ -68,11 +71,11 @@ class WaterMarkBase
 		switch ($this->type) {
 			case 'image':
 				$image = new Image();
-				$image->waterMark($filePath, $this->water, 1);
+				$image->waterMark($filePath, $this->water, 1, $this->water2);
 				break;
 			case 'pdf':
 				$pdf = new Pdf();
-				$pdf->waterMark($filePath, $this->water);
+				$pdf->waterMark($filePath, $this->water, 1, $this->water2);
 				break;
 		}
 

+ 6 - 5
dyu/application/common/service/watermark/image/Image.php

@@ -20,7 +20,7 @@ class Image
 	 * @return bool
 	 * @throws
 	 */
-	public function waterMark($filePath, $waterText, $type = 0)
+	public function waterMark($filePath, $waterText, $type = 0, $waterText2 = '')
 	{
 		// 1 打开海报背景图
 		$editor = Grafika::createEditor(['Gd']);
@@ -42,15 +42,12 @@ class Image
 			$fontSizeArr = $this->get_text_box($waterText, $fontSize, $fontPath);
 			$fontX       = intval(($size[0] * (($hypo - $fontSizeArr[0]) / 2)) / $hypo);
 			$fontY       = $size[1] - intval(($size[1] * (($hypo - $fontSizeArr[0]) / 2)) / $hypo);
-//			dump($fontX);
-//			dump($fontY);
-//			die();
 			//计算倾斜角度
 			$angle = intval(atan($size[1] / $size[0]) * 180 / pi());
 			$image = imagecreatetruecolor($size[0], $size[1]);
 		} else {
 			// 判断文字图片开始的位置
-			$fontSize = $size[0] / $fontNum ;
+			$fontSize = $size[0] / $fontNum;
 			// 获取文字大小宽高
 			$fontSizeArr = $this->get_text_box($waterText, $fontSize, $fontPath);
 			$fontX       = 0;
@@ -68,6 +65,10 @@ class Image
 		//设置文字颜色
 		$Color = new Color('#CCCCCC');
 		$editor->text($fontImage, $waterText, $fontSize, $fontX, $fontY, $Color, $fontPath, $angle);
+		if($waterText2){
+			$editor->text($fontImage, $waterText2, $fontSize, $fontX + $fontSize, $fontY + $fontSize, $Color, $fontPath, $angle);
+		}
+
 		//合并图片
 		$editor->blend($backdropImage, $fontImage, 'overlay', 1, 'center');
 		// 保存图片

+ 4 - 3
dyu/application/common/service/watermark/pdf/Pdf.php

@@ -45,6 +45,7 @@ class Pdf
 	/**
 	 * [waterMark]
 	 * 打印水印
+	 *
 	 * @Author: Yeshihao
 	 * @DateTime: 2024/11/28 13:39
 	 * @param     $filePath
@@ -56,21 +57,21 @@ class Pdf
 	 * @throws \setasign\Fpdi\PdfParser\PdfParserException
 	 * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException
 	 */
-	public function waterMark($filePath, $waterText, $type = 0)
+	public function waterMark($filePath, $waterText, $type = 0, $waterText2 = '')
 	{
 		$defaultConfig          = (new ConfigVariables())->getDefaults();
 		$fontDirs               = $defaultConfig['fontDir'];
 		$defaultFontConfig      = (new FontVariables())->getDefaults();
 		$fontData               = $defaultFontConfig['fontdata'];
 		$mpdf                   = new Mpdf(['mode'         => '+aCJK',
-		                                    'fontDir'      => array_merge($fontDirs,[__DIR__.'/fonts']),
+		                                    'fontDir'      => array_merge($fontDirs, [__DIR__.'/fonts']),
 		                                    'fontdata'     => $fontData + ['msyh' => ['R' => 'msyh.ttf',],],
 		                                    'default_font' => 'msyh'
 		]);
 		$mpdf->autoScriptToLang = true;
 		$mpdf->autoLangToFont   = true;
 
-		$text = $waterText;
+		$text = $waterText.$waterText2;
 		//文字水印
 		$watermarkText = new \Mpdf\WatermarkText($text, 30, 30, '#cccccc', 0.2);
 		$mpdf->SetWatermarkText($watermarkText, 0.3);

+ 1 - 1
dyu/application/store/model/CertificateApply.php

@@ -107,7 +107,7 @@ class CertificateApply extends CertificateApplyModel
 				return false;
 			}
 			foreach ($certificateList as $certificate) {
-				$service       = new WaterMarkBase($certificate['file']['file_path'], $this['watermark'].'有效期至'.$this['indate'], self::$wxapp_id, $certificate['file_type']);
+				$service       = new WaterMarkBase($certificate['file']['file_path'], $this['watermark'], self::$wxapp_id, $certificate['file_type'], '有效期至'.$this['indate']);
 				$result        = $service->waterMark();
 				$result_data[] = [
 					'name'           => $certificate['name'],