作者 lyh

gx

@@ -323,30 +323,21 @@ class CosService @@ -323,30 +323,21 @@ class CosService
323 */ 323 */
324 public function cropAndUploadFromCos($pathUrl,$maxHeight = 300){ 324 public function cropAndUploadFromCos($pathUrl,$maxHeight = 300){
325 $cos = config('filesystems.disks.cos'); 325 $cos = config('filesystems.disks.cos');
326 - $cosClient = new Client([  
327 - 'region' => $cos['region'],  
328 - 'credentials' => [  
329 - 'secretId' => $cos['credentials']['secretId'],  
330 - 'secretKey' => $cos['credentials']['secretKey'],  
331 - ],  
332 - ]); 326 + $url = 'https://' . $cos['bucket'] . '.cos.' . $cos['region'] . '.myqcloud.com/' . ltrim($pathUrl, '/') . '?image/info';
333 try { 327 try {
334 - $result = $cosClient->HeadObject([  
335 - 'Bucket' => $cos['bucket'],  
336 - 'Key' => $pathUrl,  
337 - 'CIProcess' => 'image/info',  
338 - ]);  
339 - @file_put_contents(storage_path('logs/crop_image_error.log'), var_export($result, true) . PHP_EOL, FILE_APPEND);  
340 - $info = simplexml_load_string($result['Body']);  
341 - @file_put_contents(storage_path('logs/crop_image_error.log'), var_export($info, true) . PHP_EOL, FILE_APPEND);  
342 - $height = (int) $info->ImageHeight;  
343 - if($height > $maxHeight){  
344 - return $this->cropCosImage($pathUrl); 328 + $xml = @file_get_contents($url);
  329 + if (!$xml) {
  330 + return '';
345 } 331 }
346 - }catch (\Exception $e){  
347 - @file_put_contents(storage_path('logs/crop_image_error.log'), var_export($e->getMessage(), true) . PHP_EOL, FILE_APPEND); 332 + $info = simplexml_load_string($xml);
  333 + if ($info === false || !isset($info->ImageHeight)) {
  334 + return '';
  335 + }
  336 + return (int) $info->ImageHeight;
  337 + } catch (\Exception $e) {
  338 + @file_put_contents(storage_path('logs/crop_image_error.log'), '获取图片高度失败: ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
  339 + return '';
348 } 340 }
349 - return true;  
350 } 341 }
351 342
352 /** 343 /**