作者 lyh

列表页聚合页模式

... ... @@ -35,13 +35,26 @@ class AiVideoController extends BaseController
Log::channel('ai_video')->info('当前数据不存在或已被删除'.$this->param['id']);
}
$cosService = new CosService();
$imagePath = $cosService->uploadRemote(1,'video',$data['url']);
if($imagePath){
//裁剪图片为4张
}else{
Log::channel('ai_video')->info('上传图片失败');
$imagePath = $cosService->uploadRemote($info['project_id'],'video',$data['url']);
try {
if($imagePath){
$cos = config('filesystems.disks.cos');
$url = $cos['cdn1'].'/'.$imagePath;
//裁剪图片为4张
$cosService = new CosService();
$images = [];
$data = $cosService->cropAndUploadToCOS($url);
if(!empty($data)){
foreach ($data as $item){
$images[] = ['url'=>$item,'alt'=>''];
}
}
$images = array_merge($images,$info['images']);
$aiVideoAutoLogModel->edit(['images'=>$images,'result'=>json_encode($this->param,true)],['id'=>$info['id']]);
}
}catch (\Exception $e){
Log::channel('ai_video')->info('上传图片失败'.$e->getMessage());
}
$this->response('success');
}
}
... ...
... ... @@ -144,7 +144,6 @@ class CosService
if(!$body_str){
return '';
}
try {
$cosClient->putObject([
'Bucket' => $cos['bucket'],
... ... @@ -421,6 +420,8 @@ class CosService
// 6. 循环裁剪并上传
$resultPaths = [];
$index = 0;
$cos = config('filesystems.disks.cos');
for ($y = 0; $y < 2; $y++) {
for ($x = 0; $x < 2; $x++) {
$crop = imagecreatetruecolor($halfWidth, $halfHeight);
... ... @@ -438,7 +439,7 @@ class CosService
'Body' => fopen($tempCropped, 'rb'),
]);
// 返回相对路径
$resultPaths[] = $objectKey;
$resultPaths[] = $cos['cdn1'].'/'.$objectKey;
unlink($tempCropped);
}
}
... ...