refactor: 后面横幅分页接口图片输出修改为缩略图

This commit is contained in:
2025-06-05 09:51:23 +08:00
parent 3635ed5284
commit 97d44527c1
3 changed files with 34 additions and 32 deletions

View File

@@ -102,4 +102,34 @@ if (!function_exists('array_to_tree')) {
}
return $ret;
}
}
if (!function_exists('thumb')) {
/**
* 获取缩略图
* @param string $url 图片地址
* @return string
*/
function thumb(?string $url): string
{
if (empty($url)) {
return '';
}
if (
str_contains($url, '_thumb') ||
\think\helper\Str::startsWith($url, ['http://', 'https://']) ||
!\think\helper\Str::endsWith($url, ['.png', '.jpg', '.jpeg', '.gif', '.tif', '.svg', '.webp', '.bmp'])
) {
return $url;
}
$idx = mb_strripos($url, '.', 0, 'utf-8');
if ($idx === false) {
return $url;
}
$len = mb_strlen($url, 'utf-8');
return mb_substr($url, 0, $idx, 'utf-8') . '_thumb' . mb_substr($url, $idx, $len - $idx, 'utf-8');
}
}