Browse Source

api端,用户七牛云上传,加水印

lizhen_gitee 1 year ago
parent
commit
735d2f06f3
2 changed files with 21 additions and 12 deletions
  1. 21 0
      addons/qiniu/controller/Index.php
  2. 0 12
      application/common.php

+ 21 - 0
addons/qiniu/controller/Index.php

@@ -227,11 +227,32 @@ class Index extends Controller
             $data['storage'] = 'qiniu';
             Attachment::create($data, true);
 
+            //水印
+            if(in_array($suffix,['jpg','png','bmp','jpeg']))
+            {
+                $username = \app\common\library\Auth::instance()->username;
+                $url.= $this->water_param($username);
+            }
+            //水印
+
             $this->success("上传成功", '', ['url' => $url, 'fullurl' => cdnurl($url, true), 'hash' => $hash]);
         }
     }
 
     /**
+     * 七牛云水印链接
+     * 传入用户展示id
+     * https://developer.qiniu.com/dora/1316/image-watermarking-processing-watermark
+     */
+    public function water_param($username = ''){
+        $shuiyin_img = 'kodo://tken'.config('site.shuiyin') ?: 'kodo://tken/logo.png';
+        $username    = !empty($username) ? $username : 'Tken';
+        $param_str = '?watermark/3/image/'.base64_encode($shuiyin_img).'/dissolve/50/ws/0.1/wst/0/text/'.base64_encode('@'.$username).'/fontsize/300/dissolve/80/gravity/SouthWest/dx/20/dy/20/fill/'.base64_encode('#FFFFFF');
+
+        return $param_str;
+    }
+
+    /**
      * 通知回调
      */
     public function notify()

+ 0 - 12
application/common.php

@@ -853,15 +853,3 @@ if (!function_exists('httpurllocal')) {
     }
 }
 
-/**
- * 七牛云水印链接
- * 传入用户展示id
- * https://developer.qiniu.com/dora/1316/image-watermarking-processing-watermark
- */
-function water_param($username){
-    $shuiyin_img = 'kodo://tken'.config('site.shuiyin') ?: 'kodo://tken/logo.png';
-    $username    = !empty($username) ? $username : 'Tken';
-    $param_str = '?watermark/3/image/'.base64_encode($shuiyin_img).'/dissolve/50/ws/0.1/wst/0/text/'.base64_encode('@'.$username).'/fontsize/300/dissolve/80/gravity/SouthWest/dx/20/dy/20/fill/'.base64_encode('#FFFFFF');
-
-    return $param_str;
-}