增加缩略图开关
parent
de5db35c86
commit
8d7bff2110
|
@ -78,8 +78,7 @@ Deny from all
|
|||
|
||||
#### 程序升级
|
||||
|
||||
- 保存好config.php文件和上传目录
|
||||
- 如果增加过Token请保存api_key.php文件
|
||||
- 保存config目录和上传目录
|
||||
- 将新程序下载至网站目录解压覆盖,然后将保存的文件替换既完成升级
|
||||
|
||||
<details><summary><mark><font color=darkred>点击查看2.0版更新日志</font></mark></summary>
|
||||
|
@ -89,6 +88,7 @@ Deny from all
|
|||
- 增加后台设置提示
|
||||
- 增加更改网站配色
|
||||
- 增加以源文件名称命名
|
||||
- 增加两种缩略图生成方式
|
||||
- 修复开启前端压缩导致的上传图片异常
|
||||
|
||||
* 2021-12-25 v2.4.4
|
||||
|
|
|
@ -307,14 +307,21 @@ if (isset($_POST['radio'])) {
|
|||
<div class="switch">
|
||||
<input type="hidden" name="compress" value="0">
|
||||
<input type="checkbox" name="compress" value="1" <?php if ($config['compress']) {echo 'checked="checked"';} ?> title=" 轻微有损压缩图片, 此压缩有可能使图片变大!特别是小图片 也有一定概率改变图片方向">
|
||||
<label style="font-weight: bold">压缩图片 - 会增加服务器负担</label>
|
||||
<label style="font-weight: bold">后端压缩图片 - 效果好于前端</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="switch">
|
||||
<input type="hidden" name="thumbnail" value="0">
|
||||
<input type="checkbox" name="thumbnail" value="1" <?php if ($config['thumbnail']) {echo 'checked="checked"';} ?> title=" 开启缩略图后会影响前端上传速度和服务器开销">
|
||||
<label style="font-weight: bold">缩略图 - 会增加服务器压力</label>
|
||||
<div>
|
||||
<label>缩略图生成 - 关闭缩略图无任何服务器开销但增加输出流量,浏览生成要比实时生成更好</label>
|
||||
</div>
|
||||
<div class="radio-primary">
|
||||
<input type="radio" name="thumbnail" value="0" <?php if($config['thumbnail']===0){echo 'checked="checked"';}?> id="thumbnail0"><label for="thumbnail0"> 关闭缩略图生成 - 广场直接输出上传图片</label>
|
||||
</div>
|
||||
<div class="radio-primary">
|
||||
<input type="radio" name="thumbnail" value="1" <?php if($config['thumbnail']===1){echo 'checked="checked"';}?> id="thumbnail1"><label for="thumbnail1"> 实时生成 - 每次都会请求服务器,不会影响广场页面布局但会增加服务器开销</label>
|
||||
</div>
|
||||
<div class="radio-primary">
|
||||
<input type="radio" name="thumbnail" value="2" <?php if($config['thumbnail']===2){echo 'checked="checked"';}?> id="thumbnail2"><label for="thumbnail2"> 客户浏览广场时生成 - 每日首张缩略图会使首次访问广场页面布局异常[刷新即可]</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
|
@ -397,11 +404,11 @@ if (isset($_POST['radio'])) {
|
|||
<label for="exampleInputInviteCode1">压缩文件夹内图片(格式:2021/05/10/):</label>
|
||||
<input type="text" class="form-control form-date" placeholder="" name="folder" value="<?php echo date('Y/m/d/'); ?>" readonly="">
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label><input type="radio" name="type" value="Imgcompress" checked="checked"> 使用本地压缩(默认上传已压缩,不需重复压缩)</label>
|
||||
<div class="radio-primary">
|
||||
<input type="radio" name="type" value="Imgcompress" id="Imgcompress" checked="checked"><label for="Imgcompress"> 使用本地压缩(默认上传已压缩,不需重复压缩)</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label><input type="radio" name="type" value="TinyImg"> 使用TinyImag压缩(需要申请key) </label>
|
||||
<div class="radio-primary">
|
||||
<input type="radio" name="type" value="TinyImg" id="TinyImg"><label for="TinyImg"> 使用TinyImag压缩(需要申请key)</label>
|
||||
</div>
|
||||
<div>
|
||||
<label>* 如果页面长时间没有响应,表示正面正在压缩!</label>
|
||||
|
@ -532,11 +539,12 @@ if (isset($_POST['radio'])) {
|
|||
$url = $config['imgurl'] . $config['path'] . 'suspic/' . $cache_file[$i]; // 图片网络连接
|
||||
$unlink_img = $config['domain'] . '/application/del.php?url=' . $url; // 图片删除连接
|
||||
// 缩略图文件
|
||||
$thumb_cache_file = $config['domain'] . '/application/thumb.php?img=' . $file_path . '&width=300&height=300';
|
||||
// $thumb_cache_file = $config['domain'] . '/application/thumb.php?img=' . $file_path . '&width=300&height=300';
|
||||
|
||||
echo '
|
||||
<tr>
|
||||
<td>' . $i . '</td>
|
||||
<td><img data-toggle="lightbox" src="' . $thumb_cache_file . '" data-image="' . $thumb_cache_file . '" class="img-thumbnail" ></td>
|
||||
<td><img data-toggle="lightbox" src="' . get_online_thumbnail($file_path) . '" data-image="' . get_online_thumbnail($file_path) . '" class="img-thumbnail" ></td>
|
||||
<td>' . $filen_name . '</td>
|
||||
<td>' . $file_size . '</td>
|
||||
<td><a class="btn btn-mini" href="' . $url . '" target="_blank">查看原图</a></td>
|
||||
|
|
|
@ -608,6 +608,86 @@ function return_thumbnail_images($url)
|
|||
}
|
||||
}
|
||||
|
||||
// 在线输出缩略图
|
||||
function get_online_thumbnail($imgUrl)
|
||||
{
|
||||
global $config;
|
||||
if ($config['thumbnail']) {
|
||||
$imgUrl = str_replace($config['imgurl'], '', $imgUrl);
|
||||
return $config['domain'] . '/application/thumb.php?img=' . $imgUrl . '&width=300&height=300';
|
||||
} else {
|
||||
return $imgUrl;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户浏览广场的时候生成缩略图,由此解决上传生成缩略图时服务器超时响应
|
||||
* @param $imgUrl 源图片网址
|
||||
* @return string 缩略图地址
|
||||
*/
|
||||
function creat_thumbnail_by_list($imgUrl)
|
||||
{
|
||||
global $config;
|
||||
|
||||
// 关闭生成和输出缩略图浏览
|
||||
if ($config['thumbnail'] === 0) {
|
||||
return $imgUrl;
|
||||
}
|
||||
// 如果是实时生成
|
||||
if ($config['thumbnail'] === 1) {
|
||||
return get_online_thumbnail($imgUrl);
|
||||
}
|
||||
|
||||
|
||||
// 将网址图片转换为相对路径
|
||||
$pathName = str_replace($config['imgurl'], '', $imgUrl);
|
||||
|
||||
// 图片绝对路径
|
||||
$abPathName = APP_ROOT . $pathName;
|
||||
|
||||
// 如果图像是gif则直接返回网址
|
||||
if (isAnimatedGif($abPathName)) {
|
||||
|
||||
return $imgUrl;
|
||||
} else {
|
||||
|
||||
// 将网址中的/i/去除
|
||||
$pathName = str_replace($config['path'], '', $pathName);
|
||||
|
||||
// 将文件的/转换为_
|
||||
$pathName = str_replace('/', '_', $pathName);
|
||||
|
||||
// 缓存文件是否存在
|
||||
if (file_exists(APP_ROOT . $config['path'] . 'thumbnails/' . $pathName)) {
|
||||
// 存在则返回缓存文件
|
||||
return $config['imgurl'] . $config['path'] . 'thumbnails/' . $pathName;
|
||||
} else {
|
||||
// 创建缓存文件并输出文件链接
|
||||
require_once __DIR__ . '/class.thumb.php';
|
||||
|
||||
// 获取文件名
|
||||
$imgName = basename($imgUrl);
|
||||
|
||||
// cache目录的绝对路径
|
||||
$cache_path = APP_ROOT . $config['path'] . 'thumbnails/';
|
||||
|
||||
// 创建cache目录
|
||||
if (!is_dir($cache_path)) {
|
||||
mkdir($cache_path, 0777, true);
|
||||
}
|
||||
|
||||
// 缩略图缓存的绝对路径
|
||||
$new_imgName = APP_ROOT . $config['path'] . 'thumbnails/' . date('Y_m_d') . '_' . $imgName;
|
||||
|
||||
// 创建并保存缩略图
|
||||
Thumb::out($abPathName, $new_imgName, 300, 300);
|
||||
|
||||
// 输出缩略图
|
||||
return $new_imgName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前页面完整URL地址
|
||||
* 返回 http://localhost/ww/index.php
|
||||
|
@ -676,14 +756,3 @@ function writefile($filename, $writetext, $openmod = 'w')
|
|||
return false;
|
||||
}
|
||||
}
|
||||
// 在线输出缩略图
|
||||
function get_online_thumbnail($imgUrl)
|
||||
{
|
||||
global $config;
|
||||
if ($config['thumbnail']) {
|
||||
$imgUrl = str_replace($config['imgurl'], '', $imgUrl);
|
||||
return $config['domain'] . '/application/thumb.php?img=' . $imgUrl . '&width=300&height=300';
|
||||
} else {
|
||||
return $imgUrl;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ if (!$config['showSwitch'] and !is_online()) {
|
|||
echo '
|
||||
<div class="col-md-4 col-sm-6 col-lg-3">
|
||||
<div class="card">
|
||||
<li><img data-image="' . get_online_thumbnail($imgUrl) . '" src="../public/images/loading.svg" data-original="' . $imgUrl . '" alt="简单图床-EasyImage"></li>
|
||||
<li><img data-image="' . creat_thumbnail_by_list($imgUrl) . '" src="../public/images/loading.svg" data-original="' . $imgUrl . '" alt="简单图床-EasyImage"></li>
|
||||
<div class="bottom">
|
||||
<a href="' . $imgUrl . '" target="_blank"><i class="icon icon-picture" title="打开原图" style="margin-left:10px;"></i></a>
|
||||
<a href="#" class="copy" data-clipboard-text="' . $imgUrl . '" title="复制文件" style="margin-left:10px;"><i class="icon icon-copy"></i></a>
|
||||
|
|
Loading…
Reference in New Issue