Selaa lähdekoodia

Merge commit '183539b0d4011a7ad5380b5bf855af42bbe2a7b7' into prod-v1

Mark 1 vuosi sitten
vanhempi
sitoutus
1eec293234

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

@@ -33,6 +33,8 @@ class WaterMarkBase
 	public $wxapp_id;
 
 	public $type;
+	public $width;
+	public $height;
 
 	public $tempDownloadFileName;
 
@@ -43,13 +45,15 @@ class WaterMarkBase
 	 * @param $water //水印内容
 	 * @param $wxapp_id //wxappid
 	 */
-	public function __construct($url, $water, $wxapp_id, $type = 'image', $water2 = '')
+	public function __construct($url, $water, $wxapp_id, $type = 'image', $water2 = '', $width = 0, $height = 0)
 	{
 		$this->url      = $url;
 		$this->water    = $water;
 		$this->water2   = $water2;
 		$this->wxapp_id = $wxapp_id;
 		$this->type     = $type;
+		$this->width    = $width;
+		$this->height   = $height;
 	}
 
 	/**
@@ -71,11 +75,11 @@ class WaterMarkBase
 		switch ($this->type) {
 			case 'image':
 				$image = new Image();
-				$image->waterMark($filePath, $this->water, 1, $this->water2);
+				$image->waterMark($filePath, $this->water, 1, $this->water2,$this->width,$this->height);
 				break;
 			case 'pdf':
 				$pdf = new Pdf();
-				$pdf->waterMark($filePath, $this->water, 1, $this->water2);
+				$pdf->waterMark($filePath, $this->water, 1, $this->water2,$this->width,$this->height);
 				break;
 		}
 

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

@@ -20,7 +20,7 @@ class Image
 	 * @return bool
 	 * @throws
 	 */
-	public function waterMark($filePath, $waterText, $type = 0, $waterText2 = '')
+	public function waterMark($filePath, $waterText, $type = 0, $waterText2 = '', $width = 0, $height = 0)
 	{
 		// 1 打开海报背景图
 		$editor = Grafika::createEditor(['Gd']);
@@ -60,12 +60,12 @@ class Image
 		$frontImageSource = imagecolorallocatealpha($image, 0, 0, 0, 127);
 		imagefill($image, 0, 0, $frontImageSource);
 		//生成文字透明背景板
-		$fontImage = new \Grafika\Gd\Image($image, '', imagesx($image), imagesy($image), ImageType::PNG);
+		$fontImage = new \Grafika\Gd\Image($image, '', imagesx($image), imagesy($image), ImageType::JPEG);
 
 		//设置文字颜色
-		$Color = new Color('#CCCCCC');
+		$Color = new Color('#000000');
 		$editor->text($fontImage, $waterText, $fontSize, $fontX, $fontY, $Color, $fontPath, $angle);
-		if($waterText2){
+		if ($waterText2) {
 			$editor->text($fontImage, $waterText2, $fontSize, $fontX + $fontSize, $fontY + $fontSize, $Color, $fontPath, $angle);
 		}
 
@@ -73,6 +73,8 @@ class Image
 		$editor->blend($backdropImage, $fontImage, 'overlay', 1, 'center');
 		// 保存图片
 		$editor->save($backdropImage, $filePath);
+		dump(1);
+		die();
 		return true;
 	}
 

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

@@ -5,6 +5,7 @@ namespace app\common\service\watermark\pdf;
 use Mpdf\Mpdf;
 use Mpdf\Config\ConfigVariables;
 use Mpdf\Config\FontVariables;
+use TCPDF;
 
 /**
  * Class Pdf
@@ -26,10 +27,10 @@ class Pdf
 //		$pageCount = $pdf->setSourceFile($filePath);
 //
 //		for ($pageNo = 1; $pageNo <= $pageCount; $pageNo++) {
-//			$templateId = $pdf->importPage($pageNo);
+//$templateId = $pdf->importPage($pageNo);
 //			$pdf->AddPage();
 //			$pdf->useTemplate($templateId, ['adjustPageSize' => true]);
-//			$size     = $pdf->getTemplateSize($templateId);
+//$size = $pdf->getTemplateSize($templateId);
 //			$center_x = $size['width'] / 2;
 //			$center_y = $size['height'] / 2;
 //			$pdf->SetXY($center_x, $center_y);
@@ -57,7 +58,7 @@ class Pdf
 	 * @throws \setasign\Fpdi\PdfParser\PdfParserException
 	 * @throws \setasign\Fpdi\PdfParser\Type\PdfTypeException
 	 */
-	public function waterMark($filePath, $waterText, $type = 0, $waterText2 = '')
+	public function waterMark($filePath, $waterText, $type = 0, $waterText2 = '', $pageWidth = 210, $pageHeight = 297)
 	{
 		$defaultConfig          = (new ConfigVariables())->getDefaults();
 		$fontDirs               = $defaultConfig['fontDir'];
@@ -66,7 +67,8 @@ class Pdf
 		$mpdf                   = new Mpdf(['mode'         => '+aCJK',
 		                                    'fontDir'      => array_merge($fontDirs, [__DIR__.'/fonts']),
 		                                    'fontdata'     => $fontData + ['msyh' => ['R' => 'msyh.ttf',],],
-		                                    'default_font' => 'msyh'
+		                                    'default_font' => 'msyh',
+		                                    'format'       => [$pageWidth, $pageHeight],
 		]);
 		$mpdf->autoScriptToLang = true;
 		$mpdf->autoLangToFont   = true;

+ 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'], self::$wxapp_id, $certificate['file_type'], '有效期至'.$this['indate']);
+				$service       = new WaterMarkBase($certificate['file']['file_path'], $this['watermark'], self::$wxapp_id, $certificate['file_type'], '有效期至'.$this['indate'], $certificate['width'], $certificate['height']);
 				$result        = $service->waterMark();
 				$result_data[] = [
 					'name'           => $certificate['name'],

+ 21 - 0
dyu/application/store/view/content/certificate/add.php

@@ -15,6 +15,7 @@
                                            value="" placeholder="请输入标题" required>
                                 </div>
                             </div>
+
                             <div class="am-form-group">
                                 <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">资质分类 </label>
                                 <div class="am-u-sm-9 am-u-end">
@@ -46,6 +47,26 @@
                                     </div>
                                 </div>
                             </div>
+                            <div class="am-form-group">
+                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">文件高度 </label>
+                                <div class="am-u-sm-9 am-u-end">
+                                    <input type="text" class="tpl-form-input" name="height"
+                                           value="" placeholder="请输入文件高度">
+                                    <div class="help-block">
+                                        <small>pdf文件请填写文件高度</small>
+                                    </div>
+                                </div>
+                            </div>
+                            <div class="am-form-group">
+                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">文件宽度 </label>
+                                <div class="am-u-sm-9 am-u-end">
+                                    <input type="text" class="tpl-form-input" name="width"
+                                           value="" placeholder="请输入文件宽度">
+                                    <div class="help-block">
+                                        <small>pdf文件请填写文件宽度</small>
+                                    </div>
+                                </div>
+                            </div>
                             <div class="am-form-group">
                                 <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                     <button type="submit" class="j-submit am-btn am-btn-secondary">提交

+ 20 - 0
dyu/application/store/view/content/certificate/edit.php

@@ -55,6 +55,26 @@
                                     </div>
                                 </div>
                             </div>
+                            <div class="am-form-group">
+                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">文件高度 </label>
+                                <div class="am-u-sm-9 am-u-end">
+                                    <input type="text" class="tpl-form-input" name="height"
+                                           value="<?= $model['height'] ?>" placeholder="请输入文件高度">
+                                    <div class="help-block">
+                                        <small>pdf文件请填写文件高度</small>
+                                    </div>
+                                </div>
+                            </div>
+                            <div class="am-form-group">
+                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">文件宽度 </label>
+                                <div class="am-u-sm-9 am-u-end">
+                                    <input type="text" class="tpl-form-input" name="width"
+                                           value="<?= $model['width'] ?>" placeholder="请输入文件宽度">
+                                    <div class="help-block">
+                                        <small>pdf文件请填写文件宽度</small>
+                                    </div>
+                                </div>
+                            </div>
                             <div class="am-form-group">
                                 <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                     <button type="submit" class="j-submit am-btn am-btn-secondary">提交