增加监黄,,二级目录安装

pull/18/head
icret 2021-10-30 17:19:15 +08:00
parent 43e31ed287
commit c326f6b97f
12 changed files with 352 additions and 66 deletions

View File

@ -20,11 +20,16 @@
- [x] 支持设置图片指定宽/高 - [x] 支持设置图片指定宽/高
- [x] 支持限制最低宽度/高度上传 - [x] 支持限制最低宽度/高度上传
- [x] 支持设置广告 - [x] 支持设置广告
- [x] 图片监黄
- [x] 支持开启/关闭api上传 - [x] 支持开启/关闭api上传
- [x] 在线管理图片(增、删、改、查) - [x] 在线管理图片(增、删、改、查)
- [x] 支持网站统计 请将统计代码放入:public/static/hm.js - [x] 支持网站统计 请将统计代码放入:public/static/hm.js
- [x] 更多····· - [x] 更多·····
#### 安装文档
[https://www.kancloud.cn/easyimage/easyimage](https://www.kancloud.cn/easyimage/easyimage)
#### 注意: #### 注意:
1. 第一次访问会检查环境并在config目录下生成EasyImage.lock 1. 第一次访问会检查环境并在config目录下生成EasyImage.lock
@ -39,29 +44,6 @@
7. 下载源码后可以删除一些文件README.md,LICENSE 7. 下载源码后可以删除一些文件README.md,LICENSE
8. 欢迎加群:[623688684](https://shang.qq.com/wpa/qunwpa?idkey=3feb4e8be8f1839f71e53bf2e876de36afc6889b2630c33c877d8df5a5583a6f) 8. 欢迎加群:[623688684](https://shang.qq.com/wpa/qunwpa?idkey=3feb4e8be8f1839f71e53bf2e876de36afc6889b2630c33c877d8df5a5583a6f)
#### API上传示例
参数:
| 参数名称 | 类型 | 是否必须 | 说明 |
| :------------: | :------------: | :------------: | :------------: |
| image | file | 是 | 需上传的图片 |
| api | text | 是 | token |
html form上传示例:
```html
<form action="../index.php" method="post" enctype="multipart/form-data">
<input type="file" name="image" accept="image/*" >
<input type="text" name = "token" placeholder="在tokenList文件找到token并输入"/>
<input type="submit" />
</form>
```
api上传成功后返回json
```json
// 参数:"sucess"上传成功 "url" 图片链接 "del" 删除链接 "failed" 上传失败 "message" 错误信息
{"result":"success","url":"http:\/\/192.168.1.15\/i\/2021\/05\/03\/u34au6_2.jpg","del":"http:\/\/192.168.1.15\/api\/api-web.php?hash=XH%BB2Z%D1%08%D8%E2%D7%048%DFJ%86n%C0%06%DAD%DCP%3E%CF%C4%1B%60%E5%C4Pli"}
```
#### 安全配置 #### 安全配置
- Apache配置文件默认设置上传目录不可运行 - Apache配置文件默认设置上传目录不可运行
@ -83,6 +65,10 @@ RewriteRule config/(.*).(php)$ [F]
- 或者参考:[https://www.545141.com/981.html](https://www.545141.com/981.html) - 或者参考:[https://www.545141.com/981.html](https://www.545141.com/981.html)
<details><summary><mark><font color=darkred>点击查看2.0版更新日志</font></mark></summary> <details><summary><mark><font color=darkred>点击查看2.0版更新日志</font></mark></summary>
* 2021年10月30日
- 增加监黄接口
- 增加对php5.6-php8.0的支持
- 修复二级目录无法使用
* 2021-10-24 v2.3.0 * 2021-10-24 v2.3.0
- 将服务器环境监测改为第一次打开时自动检测如需再次展示需删除config目录下的EasyImage.lock - 将服务器环境监测改为第一次打开时自动检测如需再次展示需删除config目录下的EasyImage.lock
@ -222,7 +208,7 @@ RewriteRule config/(.*).(php)$ [F]
<hr /> <hr />
#### 兼容性 #### 兼容性
PHP需要7.0及以上版本,需要PHP支持Fileinfo、iconv、zip、mbstring、openssl 扩展,如果缺失会导致无法访问管理面板以及上传/删除图片。 PHP推荐使用PHP7.0及以上版本,需要PHP支持Fileinfo、iconv、zip、mbstring、openssl 扩展,如果缺失会导致无法访问管理面板以及上传/删除图片。
文件上传视图提供文件列表管理和文件批量上传功能,允许拖拽(需要 HTML5 支持)来添加上传文件,支持上传大图片,优先使用 HTML5旧的浏览器自动使用Flash和Silverlight的方式兼容。 文件上传视图提供文件列表管理和文件批量上传功能,允许拖拽(需要 HTML5 支持)来添加上传文件,支持上传大图片,优先使用 HTML5旧的浏览器自动使用Flash和Silverlight的方式兼容。
<hr /> <hr />

View File

@ -73,8 +73,21 @@ if (isset($_POST['delDir'])) {
<p>访问者IP<?php echo $_SERVER["REMOTE_ADDR"]; ?></p> <p>访问者IP<?php echo $_SERVER["REMOTE_ADDR"]; ?></p>
<h5>图床信息</h5> <h5>图床信息</h5>
<hr /> <hr />
<p><?php $yesterday = date("Y/m/d/", strtotime("-1 day"));echo '今日上传:' . getFileNumber(APP_ROOT . config_path()) . ' 昨日上传:' . getFileNumber(APP_ROOT . $config['path'] . $yesterday); ?></p> <p><?php $yesterday = date("Y/m/d/", strtotime("-1 day"));
echo '今日上传:' . getFileNumber(APP_ROOT . config_path()) . ' 昨日上传:' . getFileNumber(APP_ROOT . $config['path'] . $yesterday); ?></p>
<p>当前版本:<?php echo $config['version']; ?>Github版本<a href="https://github.com/icret/EasyImages2.0/releases" target="_blank"><?php echo getVersion(); ?></a></p> <p>当前版本:<?php echo $config['version']; ?>Github版本<a href="https://github.com/icret/EasyImages2.0/releases" target="_blank"><?php echo getVersion(); ?></a></p>
<p><?php
if (empty($tinyImag_key['TinyImag'])) {
echo '压缩图片 TinyImag Key未填写申请地址<a href="https://tinypng.com/developers" target="_blank">https://tinypng.com/developers</a><br/>';
} else {
echo '压缩图片 TinyImag Key已填写<br/>';
}
if (empty($moderatecontent['key'])) {
echo '图片检查 moderatecontent key未填写申请地址 <a href="https://moderatecontent.com/" target="_blank">https://moderatecontent.com/</a>';
} else {
echo '图片检查 moderatecontent key已填写';
}
?></p>
</div> </div>
</div> </div>
</div> </div>
@ -84,9 +97,7 @@ if (isset($_POST['delDir'])) {
<form class="form-condensed" action="<?php $_SERVER['PHP_SELF']; ?>" method="post"> <form class="form-condensed" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<label for="exampleInputMoney1"> <label for="exampleInputMoney1">
新Token需按要求填入 新Token需按要求填入
<code> <code>/config/api_key.php</code>
/config/api_key.php
</code>
才生效 才生效
</label> </label>
<div class="input-group"> <div class="input-group">
@ -126,7 +137,6 @@ if (isset($_POST['delDir'])) {
</div> </div>
</div> </div>
<div class="col-md-12"> <div class="col-md-12">
<div class="col-md-4"> <div class="col-md-4">
<form action="../libs/compressing.php" method="post" target="_blank"> <form action="../libs/compressing.php" method="post" target="_blank">
<div class="form-group"> <div class="form-group">
@ -135,12 +145,12 @@ if (isset($_POST['delDir'])) {
</div> </div>
<div class="radio"> <div class="radio">
<label> <label>
<input type="radio" name="type" value="Imgcompress" checked="checked"> 使用本地压缩(默认上传已压缩,不需重复压缩) <input type="radio" name="type" value="Imgcompress" checked="checked"> 使用本地压缩(默认上传已压缩,不需重复压缩)
</label> </label>
</div> </div>
<div class="radio"> <div class="radio">
<label> <label>
<input type="radio" name="type" value="TinyImg"> 使用TinyImag压缩需要申请key) <input type="radio" name="type" value="TinyImg"> 使用tinypng压缩申请key<a href="https://tinypng.com/" target="_blank">https://tinypng.com/</a>
</label> </label>
</div> </div>
<div> <div>
@ -181,6 +191,71 @@ if (isset($_POST['delDir'])) {
</form> </form>
</div> </div>
</div> </div>
<div class="col-md-12">
<hr>
<div class="col-md-6">
<p>
<button type="button" class="btn" data-toggle="collapse" data-target="#lis_cache">疑似违规的图片<i class="icon icon-hand-down"></i></button>
</p>
<div class="collapse" id="lis_cache">
<p>为了服务器的稳定仅显示最近20张图片监黄需要在<code>config.php</code>中开启<code>checkImg</code>属性。</p>
<p>key申请地址<a href="https://moderatecontent.com" target="_blank">https://moderatecontent.com</a></p>
<p>获得key后填入<code>/config/api_key.php</code>-><code>moderatecontent</code>属性</p>
<div class="table-responsive">
<table class="table table-hover table-bordered table-auto table-condensed table-striped">
<thead>
<tr>
<th>序号</th>
<th>缩略图</th>
<th>文件名</th>
<th>长宽(像素)</th>
<th>大小</th>
<th>查看图片</th>
<th>删除图片</th>
</tr>
</thead>
<tbody>
<?php
// 获取被隔离的文件
@$cache_dir = APP_ROOT . $config['path'] . 'cache/'; // cache目录
@$cache_file = getFile($cache_dir); // 获取所有文件
@$cache_num = count($cache_file); // 统计目录文件个数
for ($i = 0; $i < $cache_num and $i < 21; $i++) { // 循环输出文件
$file_cache_path = APP_ROOT . $config['path'] . 'cache/' . $cache_file[$i]; // 图片绝对路径
$file_path = $config['path'] . 'cache/' . $cache_file[$i]; // 图片相对路径
@$file_size = getDistUsed(filesize($file_cache_path)); // 图片大小
@$filen_name = $cache_file[$i]; // 图片名称
@list($width, $height, $type, $attr) = getimagesize($file_cache_path); // 图片长、宽、类型、属性
$url = $config['imgurl'] . $config['path'] . 'cache/' . $cache_file[$i]; // 图片网络连接
$unlink_url = $config['domain'] . '/api/del.php?url=' . $url; // 图片删除连接
// 缩略图文件
$thumb_cache_file = $config['domain'] . '/libs/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>' . $filen_name . '</td>
<td>' . $height . '*' . $width . '</td>
<td>' . $file_size . '</td>
<td><a class="btn btn-mini" href="' . $url . '" target="_blank">查看原图</a></td>
<td><a class="btn btn-mini btn-danger" href="' . $unlink_url . '" target="_blank">删除图片</a></td>
</tr>
';
}
echo '
<span class="label label-primary label-outline">总数:' . $cache_num . '</span>&nbsp;
<form action="' . $_SERVER['PHP_SELF'] . '" method="post">
<input type="hidden" name="delDir" value="/cache/" readonly="">
<button class="btn btn-danger btn-mini" ">删除全部违规图片</button>
</form>
';
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div> </div>
</div> </div>
<link href="<?php static_cdn(); ?>/public/static/zui/lib/datetimepicker/datetimepicker.min.css" rel="stylesheet"> <link href="<?php static_cdn(); ?>/public/static/zui/lib/datetimepicker/datetimepicker.min.css" rel="stylesheet">

View File

@ -23,9 +23,11 @@ if (empty($_REQUEST)) {
new $.zui.Messager("没有要删除的图片!", {type: "danger" // 定义颜色主题 new $.zui.Messager("没有要删除的图片!", {type: "danger" // 定义颜色主题
}).show(); }).show();
// 延时3.5s跳转 // 延时3.5s跳转
window.setTimeout("window.location=\'/../ \'",3500); // window.setTimeout("window.location=\'/../ \'",3500);
</script> </script>
'; ';
header("refresh:3;url=".$config['domain']."");
} elseif (isset($_GET['url'])) { } elseif (isset($_GET['url'])) {
$img = $_GET['url']; $img = $_GET['url'];
echo ' echo '
@ -55,9 +57,10 @@ if (is_online()) {
new $.zui.Messager("请登录后再删除", {type: "danger" // 定义颜色主题 new $.zui.Messager("请登录后再删除", {type: "danger" // 定义颜色主题
}).show(); }).show();
// 延时2s跳转 // 延时2s跳转
window.setTimeout("window.location=\'/../libs/login.php \'",2000); // window.setTimeout("window.location=\'/../libs/login.php \'",2000);
</script> </script>
'; ';
header("refresh:2;url=".$config['domain']."/libs/login.php");
} }
} }

View File

@ -50,3 +50,4 @@ function getIDToken($id)
} }
} }
}; };

View File

@ -1,15 +1,10 @@
<?php <?php
/** /**
* 此文件用来存放各种key * | 此文件用来存放各种key
* 2021-5-8 22:04:55 * | 2021-5-8 22:04:55
*/ */
$Api_Key = [
// 填写 TinyImag Key 申请地址https://tinypng.com/developers
'TinyImag' => '****7pPVQc9P***4Jvd2zH*****'
];
/* /*
* Token list 请在此填写需要配置Token的用户 前边编号有助于识别上传者ID * Token list 请在此填写需要配置Token的用户 前边编号有助于识别上传者ID
@ -20,3 +15,20 @@ $tokenList = array(
0 => '8337effca0ddfcd9c5899f3509b23657', 0 => '8337effca0ddfcd9c5899f3509b23657',
1 => '1c17b11693cb5ec63859b091c5b9c1b2', 1 => '1c17b11693cb5ec63859b091c5b9c1b2',
); );
$tinyImag_key = [//Api_Key
// 填写 TinyImag Key 申请地址https://tinypng.com/developers
'TinyImag' => ''
];
/**
* moderatecontent key
* 图片监黄 key https://moderatecontent.com/ 获取key并填入/config/api_key.php的图片检查key
*/
$moderatecontent = array(
'url' => 'https://api.moderatecontent.com/moderate/?key=',
'key' => ''
);

View File

@ -53,6 +53,12 @@ $config = array(
'domain' => 'http://localhost', 'domain' => 'http://localhost',
// 图片链接域名,末尾不加"/" // 图片链接域名,末尾不加"/"
'imgurl' => 'http://localhost', 'imgurl' => 'http://localhost',
// 登录上传和后台管理密码,管理用户名为admin
'password' => 'admin@123',
// 是否开启登录上传 开启:true 关闭:false
'mustLogin' => false,
// 是否开启API上传 开启:true 关闭:false
'apiStatus' => false,
/** /**
* 存储路径 前后要加"/" * 存储路径 前后要加"/"
* 可根据Apache/Nginx配置安全参考https://www.545141.com/981.html README.md * 可根据Apache/Nginx配置安全参考https://www.545141.com/981.html README.md
@ -69,15 +75,9 @@ $config = array(
*/ */
'imgName' => 'default', 'imgName' => 'default',
// 最大上传限制 默认为5M 请使用工具转换Mb http://www.bejson.com/convert/filesize/ // 最大上传限制 默认为5M 请使用工具转换Mb http://www.bejson.com/convert/filesize/
'maxSize' => 15242880, 'maxSize' => 5242880,
// 每次最多上传图片数 // 每次最多上传图片数
'maxUploadFiles' => 30, 'maxUploadFiles' => 30,
// 是否开启登录上传 开启:true 关闭:false
'mustLogin' => false,
// 登录上传和后台管理密码,管理用户名为admin
'password' => 'admin@123',
// 是否开启API上传 开启:true 关闭:false
'apiStatus' => true,
// 是否开启水印:0关闭1文字水印2图片水印 不能使用动态gif添加水印 // 是否开启水印:0关闭1文字水印2图片水印 不能使用动态gif添加水印
'watermark' => 0, 'watermark' => 0,
// 水印文字内容 // 水印文字内容
@ -99,8 +99,11 @@ $config = array(
'waterImg' => 'public/images/watermark.png', 'waterImg' => 'public/images/watermark.png',
// 允许上传的图片扩展名 // 允许上传的图片扩展名
'extensions' => "'bmp,jpg,png,tif,gif,pcx,tga,svg,webp,jpeg,tga,svg,ico'", 'extensions' => "'bmp,jpg,png,tif,gif,pcx,tga,svg,webp,jpeg,tga,svg,ico'",
// 轻微有损压缩图片 开启:true 关闭:false * 此压缩有可能使图片变大!特别是小图片 也有一定概率改变图片方向 /* 轻微有损压缩图片 开启:true 关闭:false
'compress' => true, * 此压缩有可能使图片变大!特别是小图片 也有一定概率改变图片方向
* 开启后会增加服务器负担
*/
'compress' => false,
// 转换图片为指定格式 可选:''|'png'|'jpeg'|'gif'|'bmp';默认值:'' // 转换图片为指定格式 可选:''|'png'|'jpeg'|'gif'|'bmp';默认值:''
'imgConvert' => '', 'imgConvert' => '',
// 最大上传宽度 // 最大上传宽度
@ -124,7 +127,7 @@ $config = array(
// 开启顶部广告 开启:true 关闭:false 如果想添加或修改广告请到 // 开启顶部广告 开启:true 关闭:false 如果想添加或修改广告请到
'ad_top' => false, 'ad_top' => false,
// 顶部广告内容 支持html // 顶部广告内容 支持html
'ad_top_info' =>' 'ad_top_info' => '
<div id="ad" class="col-md-12" align="center" style="padding:5px;"> <div id="ad" class="col-md-12" align="center" style="padding:5px;">
<!--广告 按照这个范例替换相应链接,如果想多几个广告,就多复制几个--> <!--广告 按照这个范例替换相应链接,如果想多几个广告,就多复制几个-->
<a href="https://app.cloudcone.com/?ref=3521" target="_blank"><img src="/public/images/ad.jpg" /></a> <a href="https://app.cloudcone.com/?ref=3521" target="_blank"><img src="/public/images/ad.jpg" /></a>
@ -133,7 +136,7 @@ $config = array(
// 开启底部广告 开启:true 关闭:false 如果想添加或修改广告请到 // 开启底部广告 开启:true 关闭:false 如果想添加或修改广告请到
'ad_bot' => false, 'ad_bot' => false,
// 底部广告内容 支持html // 底部广告内容 支持html
'ad_bot_info' =>' 'ad_bot_info' => '
<div id="ad" class="col-md-12" align="center" style="padding:5px;"> <div id="ad" class="col-md-12" align="center" style="padding:5px;">
<!--广告 按照这个范例替换相应链接,如果想多几个广告,就多复制几个--> <!--广告 按照这个范例替换相应链接,如果想多几个广告,就多复制几个-->
<a href="https://app.cloudcone.com/?ref=3521" target="_blank"><img src="/public/images/ad.jpg" /></a> <a href="https://app.cloudcone.com/?ref=3521" target="_blank"><img src="/public/images/ad.jpg" /></a>
@ -156,13 +159,11 @@ $config = array(
})(); })();
</script> </script>
<!--打赏 <!-- 自定义js举例非img.545141.com跳转
<iframe src="https://img.545141.com/sponsor/index.html" style="overflow-x:hidden;overflow-y:hidden; border:0xp none #fff; min-height:240px; width:100%;" frameborder="0" scrolling="no"></iframe>
-->
<!-- 非img.545141.com跳转
<img style="display:none" src=" " onerror=\'this.onerror=null;var currentDomain="img."+"545141." + "com"; var str1=currentDomain; str2="docu"+"ment.loca"+"tion.host"; str3=eval(str2) ;if( str1!=str3 ){ do_action = "loca" + "tion." + "href = loca" + "tion.href" + ".rep" + "lace(docu" +"ment"+".loca"+"tion.ho"+"st," + "currentDomain" + ")";eval(do_action) }\' /> <img style="display:none" src=" " onerror=\'this.onerror=null;var currentDomain="img."+"545141." + "com"; var str1=currentDomain; str2="docu"+"ment.loca"+"tion.host"; str3=eval(str2) ;if( str1!=str3 ){ do_action = "loca" + "tion." + "href = loca" + "tion.href" + ".rep" + "lace(docu" +"ment"+".loca"+"tion.ho"+"st," + "currentDomain" + ")";eval(do_action) }\' />
--> -->
<!-- QQ邮箱、QQ群 <!--自定义代码举例打赏、QQ邮箱、QQ群 可删除
<iframe src="https://img.545141.com/sponsor/index.html" style="overflow-x:hidden;overflow-y:hidden; border:0xp none #fff; min-height:240px; width:100%;" frameborder="0" scrolling="no"></iframe>
<a target="_blank" href="https://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&amp;email=cR0UHB4fGBwxAABfEh4c"> <a target="_blank" href="https://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&amp;email=cR0UHB4fGBwxAABfEh4c">
<i class="icon icon-envelope-alt">联系邮箱 </i></span> <i class="icon icon-envelope-alt">联系邮箱 </i></span>
</a> </a>
@ -174,6 +175,11 @@ $config = array(
', ',
// PHP插件检测-安全设置检测-版本检测 开启:true 关闭:false // PHP插件检测-安全设置检测-版本检测 开启:true 关闭:false
'checkEnv' => true, 'checkEnv' => true,
/* 图片监黄 开启:true 关闭:false
* https://moderatecontent.com/ 获取key并填入/config/api_key.php的图片检查key
* 开启后会受服务器到https://moderatecontent.com/ 速度影响,国内不建议开启!
*/
'checkImg' => false,
// 当前版本 // 当前版本
'version' => '2.3.0', 'version' => '2.3.1',
); );

View File

@ -115,4 +115,12 @@ if ($handle->uploaded) {
} }
unset($handle); unset($handle);
// 图片违规检查
if($config['checkImg']){
require_once APP_ROOT . '/config/api_key.php';
@checkImg($imageUrl);
}
} }

137
libs/class.thumb.php Executable file
View File

@ -0,0 +1,137 @@
<?php
/* Author: Dejan QQ: 673008865
* 缩略图 - 图片等比例缩放
________________ ________________ ________________
| | | | | |
| | | top | | |
|________________| | | | |
| | |________________| | |
| middle | | | | |
| | | | |________________|
|----------------| | | | |
| | | | | bottom |
| | | | | |
|________________| |________________| |________________|
*/
// namespace Thumb;
// https://github.com/aileshe/Thumb
class Thumb{
private static $img_type; # 原图片格式
/**
* 输出图象到浏览器
* @param String $filename 原图路径
* @param String $width 预生成缩略图宽度
* @param String $height 预生成缩略图高度
* @param String $valign [middle|top|bottom],默认 居中
*/
public static function show($filename, $width, $height, $valign='middle'){
$thumb = self::make($filename, $width, $height, $valign);
header('Content-Type:image/'.self::$img_type);
echo $thumb;
}
/**
* 保存缩略图文件
* @param String $filename 原图路径
* @param String $output 缩略图输出路径
* @param String $width 预生成缩略图宽度
* @param String $height 预生成缩略图高度
* @param String $valign [middle|top|bottom],默认 居中
*/
public static function out($filename, $output, $width, $height, $valign='middle'){
$thumb = self::make($filename, $width, $height, $valign);
$fh = fopen($output, 'wb'); # 二进制文件
fwrite($fh,$thumb);
fclose($fh);
}
/**
* 输出图象到浏览器并保存缩略图文件
* @param String $filename 原图路径
* @param String $output 缩略图输出路径
* @param String $width 预生成缩略图宽度
* @param String $height 预生成缩略图高度
* @param String $valign [middle|top|bottom],默认 居中
*/
public static function showOut($filename, $output, $width, $height, $valign='middle'){
$thumb = self::make($filename, $width, $height, $valign);
$fh = fopen($output, 'wb'); # 二进制文件
fwrite($fh,$thumb);
fclose($fh);
header('Content-Type:image/'.self::$img_type);
echo $thumb;
}
/**
* 缩略图生成函数
* @param String $filename 原图路径
* @param String $width 预生成缩略图宽度
* @param String $height 预生成缩略图高度
* @param String $valign [middle|top|bottom],默认 居中
* @return FileString 原始图象流
*/
private static function make($filename,$width,$height,$valign='middle'){
ini_set('gd.jpeg_ignore_warning',true);
$filetype=array(1=>'gif',2=>'jpeg',3=>'png');
# 获取图片信息
$imginfo=getimagesize($filename);
$img_w=$imginfo[0];
$img_h=$imginfo[1];
self::$img_type=$filetype[$imginfo[2]];
$thumb_h=$height; # 固定背景画布的高度
$height=$img_h/($img_w/$width); # 图片等比例缩放后的高度=原图的高度÷(原图的宽度÷背景画布固定宽带)
# 创建新的背景画布
if($height>=$thumb_h){
$thumb=imagecreatetruecolor($width,$thumb_h);
}else{
$thumb=imagecreatetruecolor($width,$height);
$thumb_h=$height;
}
# 载入要缩放的图片
$loadimg='imagecreatefrom'.self::$img_type;
$tmp_img=$loadimg($filename);
switch($valign){
case 'top':{
$dst_y=0;
break;
}
case 'middle':{
$dst_y=($img_h-$img_w/$width*$thumb_h)/2;
break;
}
case 'bottom':{
$dst_y=$img_h-$img_w/$width*$thumb_h;
break;
}
default:{
$dst_y=0;
break;
}
}
# 合成缩略图
imagecopyresampled($thumb,$tmp_img,0,0,0,$dst_y,$width,$height, $img_w, $img_h);
ob_clean();
# 展示图片
ob_start();
$showimg='image'.self::$img_type;
$showimg($thumb); # 输出原始图象流
$thumb_img = ob_get_clean();
# 释放资源
imagedestroy($tmp_img);
imagedestroy($thumb);
return $thumb_img;
}
}

View File

@ -14,7 +14,7 @@ require_once APP_ROOT . '/config/api_key.php';
*/ */
function compress($floder, $type = 'Imgcompress', $source = '') function compress($floder, $type = 'Imgcompress', $source = '')
{ {
global $Api_Key; global $tinyImag_key;
global $config; global $config;
ini_set('max_execution_time', '0'); // 脚本运行的时间以秒为单位0不限制 ini_set('max_execution_time', '0'); // 脚本运行的时间以秒为单位0不限制
@ -35,12 +35,12 @@ function compress($floder, $type = 'Imgcompress', $source = '')
} }
if ($type == 'TinyImg') { if ($type == 'TinyImg') {
if (empty($Api_Key['TinyImag'])) { if (empty($tinyImag_key['TinyImag'])) {
exit('请先申请TinyImag key并保存再试'); exit('请先申请TinyImag key并保存再试');
} }
$folder = '..' . $config['path'] . $source; $folder = '..' . $config['path'] . $source;
$tinyImg = new TinyImg(); $tinyImg = new TinyImg();
$key = $Api_Key['TinyImag']; $key = $tinyImag_key['TinyImag'];
$input = $folder; //这个文件夹下的文件会被压缩 $input = $folder; //这个文件夹下的文件会被压缩
$output = $folder; //压缩的结果会被保存到这个文件夹中 $output = $folder; //压缩的结果会被保存到这个文件夹中
$tinyImg->compressImgsFolder($key, $input, $output); $tinyImg->compressImgsFolder($key, $input, $output);

View File

@ -599,3 +599,45 @@ function deldir($dir)
return false; return false;
} }
} }
// curl访问网站并返回解码过的json信息
function get_json($img)
{
global $moderatecontent;
$url = $moderatecontent['url'] . $moderatecontent['key'] . '&url=' . $img;
$headerArray = array("Content-type:application/json;", "Accept:application/json");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36');
$output = curl_exec($ch);
curl_close($ch);
$output = json_decode($output, true);
return $output;
}
// 检查图片是否违规
function checkImg($imageUrl)
{
global $config;
$response = get_json($imageUrl);
if ($response['rating_index'] == '3') { // (1 = everyone, 2 = teen, 3 = adult)
$old_path = APP_ROOT . parse_url($imageUrl)['path']; // 提交网址中的文件路径 /i/2021/10/29/p8vypd.png
$name = basename($imageUrl); // 文件名 p8vypd.png
$new_path = APP_ROOT . $config['path'] . 'cache/' . $name; // 新路径含文件名
$cache_dir = APP_ROOT . $config['path'] . 'cache/'; // cache路径
if (is_dir($cache_dir)) { // 创建cache目录并移动
rename($old_path, $new_path);
} else {
mkdir($cache_dir, 0777, true);
rename($old_path, $new_path);
}
}
}

View File

@ -7,7 +7,7 @@ require_once APP_ROOT . '/libs/header.php';
// 提交登录 // 提交登录
if (isset($_POST['password'])) { if (isset($_POST['password'])) {
checkLogin(); checkLogin();
Header("Location:../"); header("refresh:2;url=" . $config['domain'] . "");
} }
?> ?>
@ -24,7 +24,7 @@ if (isset($_POST['password'])) {
</form> </form>
</div> </div>
</center> </center>
<script src="../public/static/md5.min.js"></script> <script src="<?php echo $config['domain']; ?>/public/static/md5.min.js"></script>
<script> <script>
function md5_post() { function md5_post() {
var password = document.getElementById('password'); var password = document.getElementById('password');
@ -36,4 +36,5 @@ if (isset($_POST['password'])) {
</script> </script>
<?php <?php
require_once APP_ROOT . '/libs/footer.php'; require_once APP_ROOT . '/libs/footer.php';

15
libs/thumb.php Executable file
View File

@ -0,0 +1,15 @@
<?php
// +----------------------------------------------------------------------
// | 把大图缩略到缩略图指定的范围内,不留白(原图会剪切掉不符合比例的右边和下边)
// | https://www.php.cn/php-ask-458473.html
// +----------------------------------------------------------------------
require_once __DIR__ . '/function.php';
require_once __DIR__ . '/class.thumb.php';
$src = isset($_GET['img']) ? APP_ROOT . $_GET['img'] : APP_ROOT . '/public/images/404.png'; // 原图路径
$width = isset($_GET['width']) ? $_GET['width'] : 200; // 预生成缩略图的宽
$height = isset($_GET['height']) ? $_GET['height'] : 200; // 预生成缩略图的高
Thumb::show($src, $width, $height);