|
...
|
...
|
@@ -10,6 +10,7 @@ use App\Jobs\CopyProjectJob; |
|
|
|
use App\Jobs\SyncImageFileJob;
|
|
|
|
use App\Models\File\ErrorFile;
|
|
|
|
use App\Models\File\Image as ImageModel;
|
|
|
|
use App\Models\File\ImageSetting;
|
|
|
|
use App\Models\File\WatermarkImage;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Services\AmazonS3Service;
|
|
...
|
...
|
@@ -339,8 +340,9 @@ class ImageController extends Controller |
|
|
|
$this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name);
|
|
|
|
//同步数据到cos
|
|
|
|
if($this->upload_location == 0){
|
|
|
|
$watermarkOptions = $this->getProjectConfig($this->cache['project_id'] ?? 0);
|
|
|
|
$cosService = new CosService();
|
|
|
|
$cosService->uploadFile($file,$this->path,$fileName);
|
|
|
|
$cosService->uploadFile($file,$this->path,$fileName,$watermarkOptions);
|
|
|
|
}else{
|
|
|
|
//TODO::上传亚马逊
|
|
|
|
$amazonS3Service = new AmazonS3Service();
|
|
...
|
...
|
@@ -356,6 +358,27 @@ class ImageController extends Controller |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取图片配置
|
|
|
|
* @name :getProjectConfig
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/8/24 11:03
|
|
|
|
*/
|
|
|
|
public function getProjectConfig($project_id = 0){
|
|
|
|
$imageSettingModel = new ImageSetting();
|
|
|
|
$settingInfo = $imageSettingModel->read(['project_id'=>$project_id]);
|
|
|
|
if($settingInfo !== false){
|
|
|
|
if($settingInfo['status'] == 1 && !empty($settingInfo['image_data'])){
|
|
|
|
return json_decode($settingInfo['image_data'],true);
|
|
|
|
}
|
|
|
|
if($settingInfo['status'] == 2 && !empty($settingInfo['str_data'])){
|
|
|
|
return json_decode($settingInfo['str_data'],true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $filename
|
|
|
|
* @remark :下载
|
|
|
|
* @name :download
|
|
...
|
...
|
@@ -606,4 +629,90 @@ class ImageController extends Controller |
|
|
|
];
|
|
|
|
return $watermarkImageModel->addReturnId($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :设置请求参数
|
|
|
|
* @name :setInputParam
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/8/24 10:31
|
|
|
|
*/
|
|
|
|
public function saveInputParam(){
|
|
|
|
$this->request->validate([
|
|
|
|
'data'=>['required'],
|
|
|
|
'is_image'=>['required'],
|
|
|
|
],[
|
|
|
|
'data.required'=>'数据',
|
|
|
|
'is_image.required'=>'请设置文本水印还是图片水印',
|
|
|
|
]);
|
|
|
|
$data = $this->param['data'];
|
|
|
|
$is_image = $this->param['is_image'];
|
|
|
|
$imageSetting = new ImageSetting();
|
|
|
|
$info = $imageSetting->read(['project_id'=>$this->cache['project_id']]);
|
|
|
|
$domain = 'http://globalso-v6-1309677403.cos.ap-hongkong.myqcloud.com';//cos域名
|
|
|
|
if($is_image){
|
|
|
|
$param = [
|
|
|
|
'image/'.$this->urlSafeBase64Encode($domain.$data['image'] ?? ''),//图片
|
|
|
|
'gravity/'.($data['gravity'] ?? 'SouthEast'),
|
|
|
|
'dx/'.($data['dx'] ?? 0),
|
|
|
|
'dy/'. ($data['dy'] ?? 0),
|
|
|
|
'batch/'.($data['batch'] ?? 0),//平铺水印功能
|
|
|
|
'dissolve/'.($data['dissolve'] ?? 50),//透明度
|
|
|
|
'degree/'.($data['degree'] ?? 0),//旋转角度设置,取值范围为0 - 360,默认0
|
|
|
|
];
|
|
|
|
if($info === false){
|
|
|
|
$imageSetting->add(['image_data'=>json_encode($param,true),'project_id'=>$this->cache['project_id']]);
|
|
|
|
}else{
|
|
|
|
$imageSetting->edit(['image_data'=>json_encode($param,true)],['project_id'=>$this->cache['project_id']]);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$param = [
|
|
|
|
'text/'.$this->urlSafeBase64Encode($data['text'] ?? ''),//文字水印名称
|
|
|
|
'gravity/'.($data['gravity'] ?? 'SouthEast'),
|
|
|
|
'dx/'.($data['dx'] ?? 10),
|
|
|
|
'dy/'. ($data['dy'] ?? 10),
|
|
|
|
'font/'.$this->urlSafeBase64Encode($data['font'] ?? 'tahoma.ttf'),//默认宋体
|
|
|
|
'fontsize/'.($data['fontsize'] ?? 24),//水印文字字体大小,单位为磅,缺省值13
|
|
|
|
'fill/'.$this->urlSafeBase64Encode($data['fill'] ?? '#3D3D3D'),//颜色
|
|
|
|
'dissolve/'.($data['dissolve'] ?? 50),//透明度
|
|
|
|
'degree/'.($data['degree'] ?? 0),//文字水印的旋转角度设置,取值范围为0 - 360,默认0
|
|
|
|
'batch/'.($data['batch'] ?? 0),//平铺水印功能
|
|
|
|
'shadow/'.($data['shadow'] ?? 0),//文字阴影效果,有效值为[0,100],默认为0,表示无阴影
|
|
|
|
];
|
|
|
|
if($info === false){
|
|
|
|
$imageSetting->add(['str_data'=>json_encode($param,true),'project_id'=>$this->cache['project_id']]);
|
|
|
|
}else{
|
|
|
|
$imageSetting->edit(['str_data'=>json_encode($param,true)],['project_id'=>$this->cache['project_id']]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->response('success');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :修改水印配置状态
|
|
|
|
* @name :editStatus
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/8/24 11:14
|
|
|
|
*/
|
|
|
|
public function editStatus(){
|
|
|
|
$this->request->validate([
|
|
|
|
'status'=>'required',
|
|
|
|
],[
|
|
|
|
'status.required'=>'状态',
|
|
|
|
]);
|
|
|
|
$imageSetting = new ImageSetting();
|
|
|
|
$info = $imageSetting->read(['project_id'=>$this->cache['project_id']]);
|
|
|
|
if($info === false){
|
|
|
|
$this->response('请先设置水印',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
if($info['status'] == 1 && !empty($info['image_data'])){
|
|
|
|
$this->response('请先设置水印',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
if($info['status'] == 2 && !empty($info['str_data'])){
|
|
|
|
$this->response('请先设置水印',Code::SYSTEM_ERROR);
|
|
|
|
}
|
|
|
|
$imageSetting->edit(['status'=>$this->param['status']],['project_id'=>$this->cache['project_id']]);
|
|
|
|
$this->response('success');
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|