作者 李宇航

合并分支 'master-server' 到 'master'

合并水印功能



查看合并请求 !717
... ... @@ -32,7 +32,7 @@ class SyncTimeFiles extends Command
public function handle()
{
$fileModel = new File();
$start = '2024-08-10 00:00:00';
$start = '2024-08-26 00:00:00';
$end = date('Y-m-d H:i:s');
$lists = $fileModel->list(['created_at'=>['between',[$start,$end]]]);
foreach ($lists as $v){
... ...
... ... @@ -207,8 +207,9 @@ class ImageController extends Controller
$fileName = $this->getOnlyFilename($name,$param['project_id'] ?? 0);
//上传到cos
if($this->upload_location == 0){
$watermarkOptions = $this->getProjectConfig($this->cache['project_id'] ?? 0);
$cosService = new CosService();
$cosService->uploadFile($files,$this->path,$fileName);
$cosService->uploadFile($files,$this->path,$fileName,false,$watermarkOptions);
}else{
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
... ... @@ -342,7 +343,7 @@ class ImageController extends Controller
if($this->upload_location == 0){
$watermarkOptions = $this->getProjectConfig($this->cache['project_id'] ?? 0);
$cosService = new CosService();
$cosService->uploadFile($file,$this->path,$fileName,$watermarkOptions);
$cosService->uploadFile($file,$this->path,$fileName,false,$watermarkOptions);
}else{
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
... ... @@ -365,37 +366,44 @@ class ImageController extends Controller
* @time :2024/8/24 11:03
*/
public function getProjectConfig($project_id = 0){
$str = '';
$imageSettingModel = new ImageSetting();
$settingInfo = $imageSettingModel->read(['project_id'=>$project_id]);
if($settingInfo !== false){
if($settingInfo['status'] == 1 && !empty($settingInfo['image_data'])){
$image_data = json_decode($settingInfo['image_data'],true);
foreach ($image_data as $k => $v){
$arr = implode('/',$v);
if ($arr[0] == 'image') {
$arr[1] = urlSafeBase64Encode($arr[1]);
if (str_starts_with($v, "image/")) {
$v = 'image/'.urlSafeBase64Encode(substr($v, strlen("image/")));
}
$image_data[$k] = $v;
}
$str = 'watermark/1/'.implode('/',$image_data);
return $str;
}
if($settingInfo['status'] == 2 && !empty($settingInfo['str_data'])){
$str_data = json_decode($settingInfo['str_data'],true);
foreach ($str_data as $k => $v){
$arr = implode('/',$v);
$arr = explode('/',$v);
if ($arr[0] == 'text') {
$arr[1] = urlSafeBase64Encode($arr[1]);
$v = implode('/',$arr);
}
if ($arr[0] == 'font') {
$arr[1] = urlSafeBase64Encode($arr[1]);
$v = implode('/',$arr);
}
if ($arr[0] == 'fill') {
$arr[1] = urlSafeBase64Encode($arr[1]);
$v = implode('/',$arr);
}
$str_data[$k] = $arr;
$str_data[$k] = $v;
}
}
$str = 'watermark/2/'.implode('/',$str_data);
return $str;
}
return null;
return $str;
}
/**
... ... @@ -726,10 +734,10 @@ class ImageController extends Controller
if($info === false){
$this->response('请先设置水印',Code::SYSTEM_ERROR);
}
if($info['status'] == 1 && !empty($info['image_data'])){
if($info['status'] == 1 && empty($info['image_data'])){
$this->response('请先设置水印',Code::SYSTEM_ERROR);
}
if($info['status'] == 2 && !empty($info['str_data'])){
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']]);
... ... @@ -753,7 +761,9 @@ class ImageController extends Controller
if(!empty($info['str_data'])){
$info['str_data'] = json_decode($info['str_data'],true);
}
$info['domain'] = 'http://globalso-v6-1309677403.cos.ap-hongkong.myqcloud.com';
}
$this->response('success',Code::SUCCESS,$info);
}
}
... ...
... ... @@ -23,7 +23,7 @@ class CosService
* @method :post
* @time :2023/7/19 15:28
*/
public function uploadFile(&$files,$path,$filename, $binary = false,$watermarkOptions = null)
public function uploadFile(&$files,$path,$filename, $binary = false,$watermarkOptions = '')
{
$cos = config('filesystems.disks.cos');
$cosClient = new Client([
... ... @@ -42,18 +42,18 @@ class CosService
];
//水印
if ($watermarkOptions) {
$options['Pic-Operations'] = json_encode([
$options['PicOperations'] = json_encode([
'is_pic_info' => 1,
'rules' => [
[
'fileid' => $filename, // 使用相同的文件名保存
'rule' => 'watermark/1/'.implode('/',$watermarkOptions),
'fileid' => $key, // 使用相同的文件名保存
'rule' => $watermarkOptions,
]
]
]);
], true);
}
// 上传文件
$cosClient->putObject($options);
$res = $cosClient->putObject($options);
@file_put_contents(storage_path('logs/lyh_error.log'), var_export($res, true) . PHP_EOL, FILE_APPEND);
return $key;
}
... ...