作者 lyh

gx

@@ -35,15 +35,10 @@ class CropImage extends Command @@ -35,15 +35,10 @@ class CropImage extends Command
35 35
36 public function handle(){ 36 public function handle(){
37 echo '测试裁剪->cs-crop:'.PHP_EOL; 37 echo '测试裁剪->cs-crop:'.PHP_EOL;
38 - $images ='https://ecdn6.globalso.com/upload/p/1/image_other/2025-05/1746675561075.jpg';  
39 - $image = str_replace_url($images);  
40 - $cosService = new CosService();  
41 - $new_url = $cosService->cropAndUploadFromCos($image);  
42 - return $new_url;  
43 -// $project_id = $this->argument('project_id');  
44 -// ProjectServer::useProject($project_id);  
45 -// $this->_action();  
46 -// DB::disconnect('custom_mysql'); 38 + $project_id = $this->argument('project_id');
  39 + ProjectServer::useProject($project_id);
  40 + $this->_action($project_id);
  41 + DB::disconnect('custom_mysql');
47 } 42 }
48 43
49 /** 44 /**
@@ -60,8 +55,9 @@ class CropImage extends Command @@ -60,8 +55,9 @@ class CropImage extends Command
60 foreach ($data as $val){ 55 foreach ($data as $val){
61 //处理图片为相对路径 56 //处理图片为相对路径
62 $image = str_replace_url($val); 57 $image = str_replace_url($val);
63 - $new_url = $cosService->cropAndUploadFromCos($image);  
64 - echo '返回的图片路径:'.$new_url.PHP_EOL; 58 + $height = $cosService->getImageHeight($image);
  59 + echo '返回的图片高度:'.$height.PHP_EOL;
  60 + $cosService->cropCosImage($image);
65 } 61 }
66 } 62 }
67 return true; 63 return true;
@@ -315,13 +315,13 @@ class CosService @@ -315,13 +315,13 @@ class CosService
315 315
316 /** 316 /**
317 * @remark :获取cos图片高度 317 * @remark :获取cos图片高度
318 - * @name :cropAndUploadFromCos 318 + * @name :getImageHeight
319 * @author :lyh 319 * @author :lyh
320 * @method :post 320 * @method :post
321 * @time :2025/5/8 10:58 321 * @time :2025/5/8 10:58
322 - * @param :pathUrl->存储桶路径 322 + * @param :pathUrl->存储桶相对路径
323 */ 323 */
324 - public function getImageHeight($pathUrl,$maxHeight = 300){ 324 + public function getImageHeight($pathUrl){
325 $cos = config('filesystems.disks.cos'); 325 $cos = config('filesystems.disks.cos');
326 $url = 'https://' . $cos['bucket'] . '.cos.' . $cos['region'] . '.myqcloud.com/' . ltrim($pathUrl, '/') . '?image/info'; 326 $url = 'https://' . $cos['bucket'] . '.cos.' . $cos['region'] . '.myqcloud.com/' . ltrim($pathUrl, '/') . '?image/info';
327 $imageInfo = @getimagesize($url); 327 $imageInfo = @getimagesize($url);
@@ -340,10 +340,9 @@ class CosService @@ -340,10 +340,9 @@ class CosService
340 * @method :post 340 * @method :post
341 * @time :2025/5/8 11:06 341 * @time :2025/5/8 11:06
342 */ 342 */
343 - public function cropCosImage($cosUrl,$height = 200) 343 + public function cropCosImage($cosUrl,$height = 220)
344 { 344 {
345 $cos = config('filesystems.disks.cos'); 345 $cos = config('filesystems.disks.cos');
346 - // 初始化 COS 客户端  
347 $cosClient = new Client([ 346 $cosClient = new Client([
348 'region' => $cos['region'], 347 'region' => $cos['region'],
349 'credentials' => [ 348 'credentials' => [