|
...
|
...
|
@@ -323,29 +323,20 @@ class CosService |
|
|
|
*/
|
|
|
|
public function cropAndUploadFromCos($pathUrl,$maxHeight = 300){
|
|
|
|
$cos = config('filesystems.disks.cos');
|
|
|
|
$cosClient = new Client([
|
|
|
|
'region' => $cos['region'],
|
|
|
|
'credentials' => [
|
|
|
|
'secretId' => $cos['credentials']['secretId'],
|
|
|
|
'secretKey' => $cos['credentials']['secretKey'],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
$url = 'https://' . $cos['bucket'] . '.cos.' . $cos['region'] . '.myqcloud.com/' . ltrim($pathUrl, '/') . '?image/info';
|
|
|
|
try {
|
|
|
|
$result = $cosClient->HeadObject([
|
|
|
|
'Bucket' => $cos['bucket'],
|
|
|
|
'Key' => $pathUrl,
|
|
|
|
'CIProcess' => 'image/info',
|
|
|
|
]);
|
|
|
|
$info = simplexml_load_string($result['Body']);
|
|
|
|
@file_put_contents(storage_path('logs/crop_image_error.log'), var_export($info, true) . PHP_EOL, FILE_APPEND);
|
|
|
|
$height = (int) $info->ImageHeight;
|
|
|
|
if($height > $maxHeight){
|
|
|
|
return $this->cropCosImage($pathUrl);
|
|
|
|
$imageInfo = @getimagesize($url);
|
|
|
|
if ($imageInfo) {
|
|
|
|
$width = $imageInfo[0];
|
|
|
|
$height = $imageInfo[1];
|
|
|
|
return "图片尺寸:宽度 {$width}px,高度 {$height}px";
|
|
|
|
} else {
|
|
|
|
return "错误:无法读取图片或链接无效";
|
|
|
|
}
|
|
|
|
}catch (\Exception $e){
|
|
|
|
@file_put_contents(storage_path('logs/crop_image_error.log'), var_export($e->getMessage(), true) . PHP_EOL, FILE_APPEND);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
@file_put_contents(storage_path('logs/crop_image_error.log'), '获取图片高度失败: ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|