作者 刘锟

update

@@ -1468,64 +1468,66 @@ function diffInHours($startTime, $endTime) @@ -1468,64 +1468,66 @@ function diffInHours($startTime, $endTime)
1468 return round($hours, 1); 1468 return round($hours, 1);
1469 } 1469 }
1470 1470
1471 -/**  
1472 - * 通过图片地址压缩图片  
1473 - * @param $url  
1474 - * @param int $width  
1475 - * @return string  
1476 - * @author Akun  
1477 - * @date 2025/09/01 15:18  
1478 - */  
1479 -function thumbImageByUrl($url, $width = 360)  
1480 -{  
1481 - if (empty($url)) {  
1482 - return $url;  
1483 - } 1471 +if (!function_exists('thumbImageByUrl')) {
  1472 + /**
  1473 + * 通过图片地址压缩图片
  1474 + * @param $url
  1475 + * @param int $width
  1476 + * @return string
  1477 + * @author Akun
  1478 + * @date 2025/09/01 15:18
  1479 + */
  1480 + function thumbImageByUrl($url, $width = 360)
  1481 + {
  1482 + if (empty($url)) {
  1483 + return $url;
  1484 + }
1484 1485
1485 - if ($width == 0) {  
1486 - return $url;  
1487 - } 1486 + if ($width == 0) {
  1487 + return $url;
  1488 + }
1488 1489
1489 - //获取图片完整访问地址  
1490 - $url_complete = getImageUrl($url, 0, 0, 0);//先用v6-file地址  
1491 - if (strpos($url_complete, 'v6-file') !== false) {  
1492 - $is_exists = checkRemoteFileExists($url_complete);  
1493 - if (!$is_exists) {  
1494 - //不存在,再用cdn地址  
1495 - $url_complete = getImageUrl($url); 1490 + //获取图片完整访问地址
  1491 + $url_complete = getImageUrl($url, 0, 0, 0);//先用v6-file地址
  1492 + if (strpos($url_complete, 'v6-file') !== false) {
  1493 + $is_exists = checkRemoteFileExists($url_complete);
  1494 + if (!$is_exists) {
  1495 + //不存在,再用cdn地址
  1496 + $url_complete = getImageUrl($url);
  1497 + }
1496 } 1498 }
1497 - }  
1498 1499
1499 - //获取与原图存储路径相同的压缩路径  
1500 - $path = parse_url($url_complete, PHP_URL_PATH);  
1501 - $path_arr = explode('.', $path);  
1502 - if (count($path_arr) != 2) {  
1503 - return $url;  
1504 - }  
1505 - $path_arr[0] = $path_arr[0] . '_thumbW' . $width;  
1506 - $key = implode('.', $path_arr); 1500 + //获取与原图存储路径相同的压缩路径
  1501 + $path = parse_url($url_complete, PHP_URL_PATH);
  1502 + $path_arr = explode('.', $path);
  1503 + if (count($path_arr) != 2) {
  1504 + return $url;
  1505 + }
  1506 + $path_arr[0] = $path_arr[0] . '_thumbW' . $width;
  1507 + $key = implode('.', $path_arr);
1507 1508
1508 - try {  
1509 - $img = \Intervention\Image\Facades\Image::make($url_complete); 1509 + try {
  1510 + $img = \Intervention\Image\Facades\Image::make($url_complete);
1510 1511
1511 - //宽度按设定,高度自动调整  
1512 - $img->resize($width, null, function ($constraint) {  
1513 - $constraint->aspectRatio();  
1514 - $constraint->upsize();  
1515 - }); 1512 + //宽度按设定,高度自动调整
  1513 + $img->resize($width, null, function ($constraint) {
  1514 + $constraint->aspectRatio();
  1515 + $constraint->upsize();
  1516 + });
1516 1517
1517 - //获取处理后的图片二进制资源  
1518 - $resource = $img->stream()->__toString(); 1518 + //获取处理后的图片二进制资源
  1519 + $resource = $img->stream()->__toString();
1519 1520
1520 - //上传存储桶  
1521 - $thumb_url = CosService::uploadRemote('', '', '', $key, $resource); 1521 + //上传存储桶
  1522 + $thumb_url = CosService::uploadRemote('', '', '', $key, $resource);
1522 1523
1523 - $url = $thumb_url ? $thumb_url : $url;  
1524 - } catch (\Exception $e) {  
1525 - Log::channel('thumb_img')->error($e->getMessage(), [$url_complete, $width]);  
1526 - } 1524 + $url = $thumb_url ? $thumb_url : $url;
  1525 + } catch (\Exception $e) {
  1526 + Log::channel('thumb_img')->error($e->getMessage(), [$url_complete, $width]);
  1527 + }
1527 1528
1528 - return $url; 1529 + return $url;
  1530 + }
1529 } 1531 }
1530 1532
1531 if (!function_exists('checkRemoteFileExists')) { 1533 if (!function_exists('checkRemoteFileExists')) {