迅睿CMS框架是一款PHP8高性能·簡單易用的CMS開源開發框架,基于MIT開源許可協議發布,免費且不限制商業使用,是免費開源的產品,以萬端互聯為設計理念,支持的微信公眾號、小程序、APP客戶端、移動端網站、PC網站等多終端式管理系統。
聯系官方銷售客服
1835022288
028-61286886
關于縮略圖截取函數dr_thumb 不能截取編輯器自動獲取的縮略圖
這個縮略圖不能使用dr_thumb($t.thumb,300,200) 來獲取小圖
如果輸出{$t.thumb}是完整的圖片路徑就不能,必須是id號才能縮略
樓主,你的這個功能是怎么搞出來的呀
在字段里面 找到編輯器這個字段 然后設置一下就好了
回復@維嘉
學習了
自制解決方案
新建 /uploadfile/ueditor_img/ 文件夾
/config/custom.php 添加
/**
* 生成縮略圖函數(支持圖片格式:gif、jpeg、png和bmp)
* @author ruxing.li
* @param string $src 源圖片路徑
* @param int $width 縮略圖寬度(只指定高度時進行等比縮放)
* @param int $width 縮略圖高度(只指定寬度時進行等比縮放)
* @param string $filename 保存路徑(不指定時直接輸出到瀏覽器)
* @return bool
*/
function mkThumbnail($src, $width = null, $height = null, $filename = null) {
if (!isset($width) && !isset($height))
return false;
if (isset($width) && $width <= 0)
if (isset($height) && $height <= 0)
$size = getimagesize($src);
//返回圖片文件的信息
//Array
//(
// [0] => 3264
// [1] => 2448
// [2] => 2
// [3] => width="3264" height="2448"
// [bits] => 8
// [channels] => 3
// [mime] => image/jpeg
//)
if (!$size)
list($src_w, $src_h, $src_type) = $size;
$src_mime = $size['mime'];
switch ($src_type) {
case 1 :
$img_type = 'gif';
break;
case 2 :
$img_type = 'jpeg';
case 3 :
$img_type = 'png';
case 15 :
$img_type = 'wbmp';
default :
}
//等比例縮放
if (!isset($width))
$width = $src_w * ($height / $src_h);
if (!isset($height))
$height = $src_h * ($width / $src_w);
//根據上傳的文件的類型來調用不同函數
$imagecreatefunc = 'imagecreatefrom' . $img_type;
$src_img = $imagecreatefunc($src);
//新建一個真彩色圖像
$dest_img = imagecreatetruecolor($width, $height);
//重采樣拷貝部分圖像并調整大小
// /**
// imagecopyresampled() 將一幅圖像中的一塊正方形區域拷貝到另一個圖像中,平滑地插入像素值,
// 因此,尤其是,減小了圖像的大小而仍然保持了極大的清晰度。
// 如果源和目標的寬度和高度不同,則會進行相應的圖像收縮和拉伸。坐標指的是左上角。
// 本函數可用來在同一幅圖內部拷貝(如果 dst_image 和 src_image 相同的話)區域,但如果區域交迭的話則結果不可預知。
// */
imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
$imagefunc = 'image' . $img_type;
if ($filename) {
$imagefunc($dest_img, $filename);
} else {
header('Content-Type: ' . $src_mime);
$imagefunc($dest_img);
//銷毀文件資源
imagedestroy($src_img);
imagedestroy($dest_img);
return true;
修改 /dayrui/Fcms/Core/Helper.php function dr_thumb
// 縮略圖
function dr_thumb($img, $width = 200, $height = 200, $water = 0, $mode = 'auto') {
if (is_numeric($img)) {
list($cache_path, $cache_url) = dr_thumb_path();
// 圖片縮略圖文件
$cache_file = md5($img).'/'.$width.'x'.$height.($water ? '_water' : '').'_'.$mode.'.jpg';
if (is_file($cache_path.$cache_file)) {
return $cache_url.$cache_file;
return \Phpcmf\Service::L('image')->thumb($img, $width, $height, $water, $mode);
}elseif(strpos($img,'ueditor') !== false){
//return ROOT_THEME_PATH.'assets/images/nopic.gif';
$new_scr = '/uploadfile/ueditor_img/';
$new_img = $width.'x'.$height.'_'.substr($img,strrpos($img,'/')+1);
if (is_file(ROOTPATH.$new_scr.$new_img)) {
return $new_scr.$new_img;
//dr_mkdirs($new_scr);
$result = mkThumbnail(ROOTPATH.$img, $width, $height, ROOTPATH.$new_scr.$new_img);
if ($result) {
$file = dr_file($img);
return $file ? $file : ROOT_THEME_PATH.'assets/images/nopic.gif';
如果輸出{$t.thumb}是完整的圖片路徑就不能,必須是id號才能縮略
樓主,你的這個功能是怎么搞出來的呀
在字段里面 找到編輯器這個字段 然后設置一下就好了
回復@維嘉
學習了
自制解決方案
新建 /uploadfile/ueditor_img/ 文件夾
/config/custom.php 添加
/**
* 生成縮略圖函數(支持圖片格式:gif、jpeg、png和bmp)
* @author ruxing.li
* @param string $src 源圖片路徑
* @param int $width 縮略圖寬度(只指定高度時進行等比縮放)
* @param int $width 縮略圖高度(只指定寬度時進行等比縮放)
* @param string $filename 保存路徑(不指定時直接輸出到瀏覽器)
* @return bool
*/
function mkThumbnail($src, $width = null, $height = null, $filename = null) {
if (!isset($width) && !isset($height))
return false;
if (isset($width) && $width <= 0)
return false;
if (isset($height) && $height <= 0)
return false;
$size = getimagesize($src);
//返回圖片文件的信息
//Array
//(
// [0] => 3264
// [1] => 2448
// [2] => 2
// [3] => width="3264" height="2448"
// [bits] => 8
// [channels] => 3
// [mime] => image/jpeg
//)
if (!$size)
return false;
list($src_w, $src_h, $src_type) = $size;
$src_mime = $size['mime'];
switch ($src_type) {
case 1 :
$img_type = 'gif';
break;
case 2 :
$img_type = 'jpeg';
break;
case 3 :
$img_type = 'png';
break;
case 15 :
$img_type = 'wbmp';
break;
default :
return false;
}
//等比例縮放
if (!isset($width))
$width = $src_w * ($height / $src_h);
if (!isset($height))
$height = $src_h * ($width / $src_w);
//根據上傳的文件的類型來調用不同函數
$imagecreatefunc = 'imagecreatefrom' . $img_type;
$src_img = $imagecreatefunc($src);
//新建一個真彩色圖像
$dest_img = imagecreatetruecolor($width, $height);
//重采樣拷貝部分圖像并調整大小
// /**
// imagecopyresampled() 將一幅圖像中的一塊正方形區域拷貝到另一個圖像中,平滑地插入像素值,
// 因此,尤其是,減小了圖像的大小而仍然保持了極大的清晰度。
// 如果源和目標的寬度和高度不同,則會進行相應的圖像收縮和拉伸。坐標指的是左上角。
// 本函數可用來在同一幅圖內部拷貝(如果 dst_image 和 src_image 相同的話)區域,但如果區域交迭的話則結果不可預知。
// */
imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $width, $height, $src_w, $src_h);
$imagefunc = 'image' . $img_type;
if ($filename) {
$imagefunc($dest_img, $filename);
} else {
header('Content-Type: ' . $src_mime);
$imagefunc($dest_img);
}
//銷毀文件資源
imagedestroy($src_img);
imagedestroy($dest_img);
return true;
}
修改 /dayrui/Fcms/Core/Helper.php function dr_thumb
// 縮略圖
function dr_thumb($img, $width = 200, $height = 200, $water = 0, $mode = 'auto') {
if (is_numeric($img)) {
list($cache_path, $cache_url) = dr_thumb_path();
// 圖片縮略圖文件
$cache_file = md5($img).'/'.$width.'x'.$height.($water ? '_water' : '').'_'.$mode.'.jpg';
if (is_file($cache_path.$cache_file)) {
return $cache_url.$cache_file;
}
return \Phpcmf\Service::L('image')->thumb($img, $width, $height, $water, $mode);
}elseif(strpos($img,'ueditor') !== false){
//return ROOT_THEME_PATH.'assets/images/nopic.gif';
$new_scr = '/uploadfile/ueditor_img/';
$new_img = $width.'x'.$height.'_'.substr($img,strrpos($img,'/')+1);
if (is_file(ROOTPATH.$new_scr.$new_img)) {
return $new_scr.$new_img;
}
//dr_mkdirs($new_scr);
$result = mkThumbnail(ROOTPATH.$img, $width, $height, ROOTPATH.$new_scr.$new_img);
if ($result) {
return $new_scr.$new_img;
}
}
$file = dr_file($img);
return $file ? $file : ROOT_THEME_PATH.'assets/images/nopic.gif';
}