|
|
|
@ -494,6 +494,7 @@ Class SiteController extends Controller {
@@ -494,6 +494,7 @@ Class SiteController extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//借助gd库,获取图片类型、尺寸,并实时生成缩略图 |
|
|
|
|
//支持imagick库 |
|
|
|
|
protected function createSmallJpg($img_filepath, $min_width = 100, $min_height = 100) { |
|
|
|
|
//如果服务器端生成缩略图关闭 |
|
|
|
|
if (!empty(FSC::$app['config']['disableGenerateSmallImageInServer']) && FSC::$app['config']['disableGenerateSmallImageInServer'] !== 'false') { |
|
|
|
@ -503,6 +504,36 @@ Class SiteController extends Controller {
@@ -503,6 +504,36 @@ Class SiteController extends Controller {
|
|
|
|
|
$img_data = null; |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
if (class_exists('Imagick')) { //Imagick库支持 |
|
|
|
|
|
|
|
|
|
$imagick = new Imagick($img_filepath); |
|
|
|
|
$naturalWidth = $imagick->getImageWidth(); |
|
|
|
|
$naturalHeight = $imagick->getImageHeight(); |
|
|
|
|
$imgType = $imagick->getImageMimeType(); |
|
|
|
|
|
|
|
|
|
//小图片则保持原图尺寸 |
|
|
|
|
if ($naturalWidth <= $min_width || $naturalHeight <= $min_height) { |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//生成同比例缩略图尺寸 |
|
|
|
|
$width = $min_width; |
|
|
|
|
$height = $min_height; |
|
|
|
|
$aspect = $naturalHeight / $naturalWidth; |
|
|
|
|
if ($naturalWidth <= $naturalHeight) { |
|
|
|
|
$height = (int)($width * $aspect); |
|
|
|
|
}else { |
|
|
|
|
$width = (int)($height / $aspect); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$imagick->scaleImage($width, $height, true); //生成缩略图,并自适应 |
|
|
|
|
$imagick->setImageFormat('jpeg'); |
|
|
|
|
$imagick->setImageCompressionQuality(90); |
|
|
|
|
$img_data = $imagick->getImageBlob(); |
|
|
|
|
$imagick->clear(); |
|
|
|
|
|
|
|
|
|
}else if (function_exists('gd_info')) { //gd库支持 |
|
|
|
|
|
|
|
|
|
list($naturalWidth, $naturalHeight, $imgTypeIndex, $style) = getimagesize($img_filepath); |
|
|
|
|
$imgType = image_type_to_extension($imgTypeIndex); |
|
|
|
|
|
|
|
|
@ -563,6 +594,8 @@ Class SiteController extends Controller {
@@ -563,6 +594,8 @@ Class SiteController extends Controller {
|
|
|
|
|
|
|
|
|
|
imagedestroy($dst_img); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}catch(Exception $e) { |
|
|
|
|
$this->logError('创建缩略图失败:' . $e->getMessage()); |
|
|
|
|
} |
|
|
|
|