|
...
|
...
|
@@ -10,10 +10,13 @@ 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;
|
|
|
|
use App\Services\CosService;
|
|
|
|
use App\Services\TencentCosService;
|
|
|
|
use App\Services\UpyunService;
|
|
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
...
|
...
|
@@ -204,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();
|
|
...
|
...
|
@@ -337,8 +341,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,false,$watermarkOptions);
|
|
|
|
}else{
|
|
|
|
//TODO::上传亚马逊
|
|
|
|
$amazonS3Service = new AmazonS3Service();
|
|
...
|
...
|
@@ -354,6 +359,54 @@ class ImageController extends Controller |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取图片配置
|
|
|
|
* @name :getProjectConfig
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @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){
|
|
|
|
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 = 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] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$str = 'watermark/2/'.implode('/',$str_data);
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $filename
|
|
|
|
* @remark :下载
|
|
|
|
* @name :download
|
|
...
|
...
|
@@ -514,4 +567,203 @@ class ImageController extends Controller |
|
|
|
$data = ['image_download'=>url('a/download_images?path='.$info['path']), 'name' => $info['name']];
|
|
|
|
$this->response('success',Code::SUCCESS,$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :覆盖原图
|
|
|
|
* @name :coverOriginalImage
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/8/21 11:45
|
|
|
|
*/
|
|
|
|
public function coverOriginalImage(){
|
|
|
|
$this->request->validate([
|
|
|
|
'old_url'=>['required'],
|
|
|
|
'url'=>['required'],
|
|
|
|
'saveUrl'=>['required'],
|
|
|
|
],[
|
|
|
|
'old_url.required'=>'原图的相对路径',
|
|
|
|
'url.required'=>'请填写预览的链接',
|
|
|
|
'saveUrl.required'=>'保存的路径',
|
|
|
|
]);
|
|
|
|
$cos = new CosService();
|
|
|
|
$url = $cos->coverOriginalImage($this->param['url'],$this->param['saveUrl']);
|
|
|
|
$this->saveWatermarkImage($this->param['saveUrl'],$this->param['old_url']);
|
|
|
|
if($this->param['saveUrl'] == $this->param['old_url']){
|
|
|
|
$upYun = new UpyunService();
|
|
|
|
$upYun->purgePush($url);
|
|
|
|
}
|
|
|
|
$this->response('success',Code::SUCCESS,['url'=>$url]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :设置图片水印
|
|
|
|
* @name :setWatermark
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/8/21 9:15
|
|
|
|
*/
|
|
|
|
public function setWatermark(){
|
|
|
|
$this->request->validate([
|
|
|
|
'url'=>['required'],
|
|
|
|
'is_image'=>['required'],
|
|
|
|
],[
|
|
|
|
'url.required'=>'请填写需要处理图片的相对路径',
|
|
|
|
'is_image.required'=>'请设置文本水印还是图片水印',
|
|
|
|
]);
|
|
|
|
$cos = new CosService();
|
|
|
|
$url = $cos->setWatermark($this->param['url'], $this->param['data'],$this->param['is_image']);
|
|
|
|
$this->response('success',Code::SUCCESS,['url'=>$url]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取字体
|
|
|
|
* @name :getFont
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/8/21 9:47
|
|
|
|
*/
|
|
|
|
public function getFont(){
|
|
|
|
$cos = new CosService();
|
|
|
|
$data = $cos->getFont();
|
|
|
|
$this->response('success',Code::SUCCESS,$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :处理9宫格数据
|
|
|
|
* @name :getPosition
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/8/21 9:47
|
|
|
|
*/
|
|
|
|
public function getPosition(){
|
|
|
|
$cos = new CosService();
|
|
|
|
$data = $cos->getPosition();
|
|
|
|
$this->response('success',Code::SUCCESS,$data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存水印图片记录
|
|
|
|
* @name :saveWatermarkImage
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/8/21 14:34
|
|
|
|
*/
|
|
|
|
public function saveWatermarkImage($path,$old_path){
|
|
|
|
$watermarkImageModel = new WatermarkImage();
|
|
|
|
$data = [
|
|
|
|
'path' => $path,
|
|
|
|
'old_path'=>$old_path,
|
|
|
|
'project_id' =>$this->cache['project_id'] ?? 0
|
|
|
|
];
|
|
|
|
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/'.$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/'.($data['text'] ?? ''),//文字水印名称
|
|
|
|
'gravity/'.($data['gravity'] ?? 'SouthEast'),
|
|
|
|
'dx/'.($data['dx'] ?? 10),
|
|
|
|
'dy/'. ($data['dy'] ?? 10),
|
|
|
|
'font/'.($data['font'] ?? 'tahoma.ttf'),//默认宋体
|
|
|
|
'fontsize/'.($data['fontsize'] ?? 24),//水印文字字体大小,单位为磅,缺省值13
|
|
|
|
'fill/'.($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');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取配置
|
|
|
|
* @name :getImageSetting
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/8/24 11:41
|
|
|
|
*/
|
|
|
|
public function getImageSetting(){
|
|
|
|
$imageSetting = new ImageSetting();
|
|
|
|
$info = $imageSetting->read(['project_id'=>$this->cache['project_id']]);
|
|
|
|
if($info !== false){
|
|
|
|
if(!empty($info['image_data'])){
|
|
|
|
$info['image_data'] = json_decode($info['image_data'],true);
|
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|