|
...
|
...
|
@@ -39,7 +39,8 @@ class CropImage extends Command |
|
|
|
echo '测试裁剪->cs-crop:'.PHP_EOL;
|
|
|
|
$project_id = $this->argument('project_id');
|
|
|
|
ProjectServer::useProject($project_id);
|
|
|
|
$this->_action($project_id);
|
|
|
|
$data = $this->_keywordAction($project_id);
|
|
|
|
$this->_aiAction($project_id,$data[0] ?? []);
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -50,22 +51,63 @@ class CropImage extends Command |
|
|
|
* @method :post
|
|
|
|
* @time :2025/5/8 9:21
|
|
|
|
*/
|
|
|
|
public function _action($project_id){
|
|
|
|
public function _keywordAction($project_id){
|
|
|
|
//聚合页裁剪
|
|
|
|
$data = $this->getKeywordImage($project_id);
|
|
|
|
if(!empty($data)){
|
|
|
|
$cosService = new CosService();
|
|
|
|
if(!empty($data)){
|
|
|
|
foreach ($data as $val){
|
|
|
|
//处理图片为相对路径
|
|
|
|
$image = str_replace_url($val);
|
|
|
|
$height = $cosService->getImageHeight($image);
|
|
|
|
if(empty($height)){
|
|
|
|
echo '未获取到图片高度。'.PHP_EOL;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
echo '返回的图片高度:'.$height.PHP_EOL;
|
|
|
|
$cosService->cropCosImage($image);
|
|
|
|
if($height > 220){
|
|
|
|
$result = $cosService->cropCosImage($image);
|
|
|
|
if(empty($result)){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$this->saveMysql($project_id,$result['size'],$result['type'],$result['path'],$result['mime']);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :ai执行方法
|
|
|
|
* @name :_aiAction
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/5/8 16:12
|
|
|
|
*/
|
|
|
|
public function _aiAction($project_id,$keywordImage){
|
|
|
|
$cosService = new CosService();
|
|
|
|
//ai_blog裁剪
|
|
|
|
$ai_image = $this->getAiBlogImage($project_id,$keywordImage ?? '');
|
|
|
|
if(empty($ai_image)){
|
|
|
|
echo '当前图片不需要裁剪。'.PHP_EOL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$height = $cosService->getImageHeight($ai_image);
|
|
|
|
if(empty($height)){
|
|
|
|
echo '未获取到AI_BLOG图片高度。'.PHP_EOL;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
echo '返回的图片高度:'.$height.PHP_EOL;
|
|
|
|
if($height > 220){
|
|
|
|
$result = $cosService->cropCosImage($ai_image);
|
|
|
|
if(empty($result)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$this->saveMysql($project_id,$result['size'],$result['type'],$result['path'],$result['mime']);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @remark :获取aiBlog图片
|
|
|
|
* @name :getAiBlogImage
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -73,17 +115,19 @@ class CropImage extends Command |
|
|
|
* @time :2025/5/8 10:42
|
|
|
|
*/
|
|
|
|
public function getAiBlogImage($project_id,$keywordImage){
|
|
|
|
$image = '';
|
|
|
|
// AI博客banner type:1:产品,2:博客,3:新闻,4:AIBlog
|
|
|
|
$webSettingImageModel = new WebSettingImage();
|
|
|
|
$aiBlogInfo = $webSettingImageModel->read(['project_id' => $project_id, 'type' => 4],['image']);
|
|
|
|
if($aiBlogInfo !== false && !empty($aiBlogInfo['image'])){
|
|
|
|
$image = getImageUrl($aiBlogInfo['image']);
|
|
|
|
if($aiBlogInfo === false && !empty($keywordImage)){
|
|
|
|
$webSettingImageModel->addReturnId(['project_id'=>$project_id,'image'=>$keywordImage,'type'=>4]);
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
if(empty($image) && !empty($keywordImage)){
|
|
|
|
$image = $keywordImage;
|
|
|
|
if(empty($aiBlogInfo['image']) && !empty($keywordImage)){
|
|
|
|
$webSettingImageModel->edit(['image'=>$keywordImage],['id'=>$aiBlogInfo['id']]);
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return $image;
|
|
|
|
$ai_image = str_replace_url($aiBlogInfo['image']);
|
|
|
|
return $ai_image;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -147,25 +191,20 @@ class CropImage extends Command |
|
|
|
* @method :post
|
|
|
|
* @time :2025/5/8 14:59
|
|
|
|
*/
|
|
|
|
public function saveMysql($size,$image_type,$fileName,$hash,$is_cos = 0,$mime = '', $name=''){
|
|
|
|
public function saveMysql($project_id,$size,$image_type,$path,$mime = ''){
|
|
|
|
$imageModel = new Image();
|
|
|
|
$data = [
|
|
|
|
'path' => $this->path.'/'.$fileName,
|
|
|
|
'created_at' => date('Y-m-d H:i:s',time()),
|
|
|
|
'path' => $path,
|
|
|
|
'size' => $size,
|
|
|
|
'hash' => $hash,
|
|
|
|
'type'=>$image_type,
|
|
|
|
'refer'=>$this->param['refer'] ?? 0,
|
|
|
|
'is_cos'=>($is_cos == 0) ? 1 : 0,
|
|
|
|
'mime'=>$mime,
|
|
|
|
'project_id'=>$this->cache['project_id'] ?? 0,
|
|
|
|
'name'=>$name,
|
|
|
|
'en_name'=>$fileName
|
|
|
|
'hash' => hash_file('sha256', $path),
|
|
|
|
'type' => $image_type,
|
|
|
|
'refer'=> 0,
|
|
|
|
'mime' => $mime,
|
|
|
|
'project_id'=>$project_id,
|
|
|
|
'name'=>basename($path),
|
|
|
|
'en_name'=>basename($path)
|
|
|
|
];
|
|
|
|
$rs = $imageModel->add($data);
|
|
|
|
if ($rs === false) {
|
|
|
|
return $this->response('添加失败', Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
$imageModel->addReturnId($data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|