Browse Source

improve small image generator, avoid zoom small image

master
filesite 4 months ago
parent
commit
6ebdf6f206
  1. 1
      conf/app.php
  2. 14
      themes/beauty/controller/SiteController.php

1
conf/app.php

@ -53,6 +53,7 @@ $configs = array(
'supportedVideoExts' => array('mp4', 'mov', 'm3u8'), 'supportedVideoExts' => array('mp4', 'mov', 'm3u8'),
'screenshot_start' => 1000, //视频播放页快照截取开始时间,单位:毫秒 'screenshot_start' => 1000, //视频播放页快照截取开始时间,单位:毫秒
'screenshot_expire_seconds' => 315360000, //视频封面图缓存3650天 'screenshot_expire_seconds' => 315360000, //视频封面图缓存3650天
'small_image_zoom_rate' => 2.5, //缩略图在最小尺寸基础上的放大倍数,以确保清晰度
'enableSmallImage' => true, //开启图片小尺寸缩略图,设置 false 则关闭 'enableSmallImage' => true, //开启图片小尺寸缩略图,设置 false 则关闭
/* /*

14
themes/beauty/controller/SiteController.php

@ -270,7 +270,7 @@ Class SiteController extends Controller {
if (empty($cachedData)) { if (empty($cachedData)) {
//从缓存数据中获取目录的realpath //从缓存数据中获取目录的realpath
$cachedData = Common::getCacheFromFile($cacheId); $cachedData = Common::getCacheFromFile($cacheId, $expireSeconds);
if (!empty($cachedData)) { if (!empty($cachedData)) {
$realpath = $cachedData[$cateId]['realpath']; $realpath = $cachedData[$cateId]['realpath'];
$scanner = new DirScanner(); $scanner = new DirScanner();
@ -374,15 +374,23 @@ Class SiteController extends Controller {
list($naturalWidth, $naturalHeight, $imgTypeIndex, $style) = getimagesize($img_filepath); list($naturalWidth, $naturalHeight, $imgTypeIndex, $style) = getimagesize($img_filepath);
$imgType = image_type_to_extension($imgTypeIndex); $imgType = image_type_to_extension($imgTypeIndex);
//小图片则保持原图尺寸
if ($naturalWidth <= $max_width || $naturalHeight <= $max_height) {
return false;
}
//生成同比例缩略图尺寸 //生成同比例缩略图尺寸
$zoomRate = FSC::$app['config']['small_image_zoom_rate']; //缩略图在最小尺寸基础上放大比例,为确保清晰度
$width = $min_width; $width = $min_width;
$height = $min_height; $height = $min_height;
$aspect = $naturalHeight / $naturalWidth; $aspect = $naturalHeight / $naturalWidth;
if ($naturalWidth <= $naturalHeight) { if ($naturalWidth <= $naturalHeight) {
$width = $width * 2.5 <= $max_width ? (int)($width * 2.5) : $max_width; if ($width * $zoomRate >= $naturalWidth) {return false;} //避免把小图片放大
$width = $width * $zoomRate <= $max_width ? (int)($width * $zoomRate) : $max_width;
$height = (int)($width * $aspect); $height = (int)($width * $aspect);
}else { }else {
$height = $height * 2.5 <= $max_height ? (int)($height * 2.5) : $max_height; if ($height * $zoomRate >= $naturalHeight) {return false;} //避免把小图片放大
$height = $height * $zoomRate <= $max_height ? (int)($height * $zoomRate) : $max_height;
$width = (int)($height / $aspect); $width = (int)($height / $aspect);
} }

Loading…
Cancel
Save