合并分支 'lyh-server' 到 'master'
Lyh server 查看合并请求 !1940
正在显示
1 个修改的文件
包含
11 行增加
和
20 行删除
| @@ -323,29 +323,20 @@ class CosService | @@ -323,29 +323,20 @@ 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 | - $info = simplexml_load_string($result['Body']); | ||
| 340 | - @file_put_contents(storage_path('logs/crop_image_error.log'), var_export($info, true) . PHP_EOL, FILE_APPEND); | ||
| 341 | - $height = (int) $info->ImageHeight; | ||
| 342 | - if($height > $maxHeight){ | ||
| 343 | - return $this->cropCosImage($pathUrl); | 328 | + $imageInfo = @getimagesize($url); |
| 329 | + if ($imageInfo) { | ||
| 330 | + $width = $imageInfo[0]; | ||
| 331 | + $height = $imageInfo[1]; | ||
| 332 | + return "图片尺寸:宽度 {$width}px,高度 {$height}px"; | ||
| 333 | + } else { | ||
| 334 | + return "错误:无法读取图片或链接无效"; | ||
| 344 | } | 335 | } |
| 345 | - }catch (\Exception $e){ | ||
| 346 | - @file_put_contents(storage_path('logs/crop_image_error.log'), var_export($e->getMessage(), true) . PHP_EOL, FILE_APPEND); | 336 | + } catch (\Exception $e) { |
| 337 | + @file_put_contents(storage_path('logs/crop_image_error.log'), '获取图片高度失败: ' . $e->getMessage() . PHP_EOL, FILE_APPEND); | ||
| 338 | + return ''; | ||
| 347 | } | 339 | } |
| 348 | - return true; | ||
| 349 | } | 340 | } |
| 350 | 341 | ||
| 351 | /** | 342 | /** |
-
请 注册 或 登录 后发表评论