|
...
|
...
|
@@ -323,30 +323,21 @@ 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',
|
|
|
|
]);
|
|
|
|
@file_put_contents(storage_path('logs/crop_image_error.log'), var_export($result, true) . PHP_EOL, FILE_APPEND);
|
|
|
|
$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);
|
|
|
|
$xml = @file_get_contents($url);
|
|
|
|
if (!$xml) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
}catch (\Exception $e){
|
|
|
|
@file_put_contents(storage_path('logs/crop_image_error.log'), var_export($e->getMessage(), true) . PHP_EOL, FILE_APPEND);
|
|
|
|
$info = simplexml_load_string($xml);
|
|
|
|
if ($info === false || !isset($info->ImageHeight)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return (int) $info->ImageHeight;
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
@file_put_contents(storage_path('logs/crop_image_error.log'), '获取图片高度失败: ' . $e->getMessage() . PHP_EOL, FILE_APPEND);
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
...
|
...
|
|