Files
EasyImages2.0/file.php
icret 2d7d5bfe66 v2.2.0
- 增加根目录静态属性
- 增加浏览页面懒加载
- 增加浏览页面启用选定日期查看图片
- 增加版本检测 ***每月10日06点和25日01点检测Github是否更新***
- 增加上传压缩 ***此压缩有可能使图片变大!特别是小图片 也有一定概率改变图片方向***
- 增加批量压缩目录 ***TinyImag或本机压缩,本机压缩出现的问题***
- 修复title
- 修复二级目录安装
- 修复对PHP5.6的兼容 ***建议使用php7.0及以上!***
2021-05-22 11:27:53 +08:00

119 lines
4.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
require __DIR__ . '/libs/function.php';
require APP_ROOT . '/libs/class.upload.php';
require APP_ROOT . '/libs/WaterMask.php';
$handle = new Upload($_FILES['file'], 'zh_CN');
if ($handle->uploaded) {
// 允许上传的mime类型
$handle->allowed = array('image/*');
// 文件命名
$handle->file_new_name_body = imgName();
// 最大上传限制
//$handle->file_max_sizes = $config['maxSize'];
// 最大宽度
$handle->image_max_width = $config['maxWidth'];
// 最大高度
$handle->image_max_height = $config['maxHeight'];
// 最小宽度
$handle->image_min_width = $config['minWidth'];
// 最小高度
$handle->image_min_height = $config['minHeight'];
// 转换图片为指定格式
$handle->image_convert = $config['imgConvert'];
/* 等比例缩减图片 放到前端了
if ($config['imgRatio']) {
$handle->image_resize = true;
$handle->image_x = $config['image_x'];
$handle->image_y = $config['image_y'];
}
*/
// 存储图片路径:images/201807/
$handle->process(APP_ROOT . config_path());
// 设置水印
if ($config['watermark'] > 0) {
switch ($config['watermark']) {
case 1: // 文字水印 过滤gif
if (isAnimatedGif($handle->file_src_pathname) === 0) {
$arr = [
# 水印图片路径(如果不存在将会被当成是字符串水印)
'res' => $config['waterText'],
# 水印显示位置
'pos' => $config['waterPosition'],
# 不指定name(会覆盖原图也就是保存成thumb.jpeg)
'name' => $handle->file_dst_pathname,
'font' => $config['textFont'],
'fontSize' => $config['textSize'],
'color' => $config['textColor'],
];
Imgs::setWater($handle->file_dst_pathname, $arr);
}
break;
case 2: // 图片水印
if (isAnimatedGif($handle->file_src_pathname) === 0) {
$arr = [
# 水印图片路径(如果不存在将会被当成是字符串水印)
'res' => $config['waterImg'],
# 水印显示位置
'pos' => $config['waterPosition'],
# 不指定name(会覆盖原图也就是保存成thumb.jpeg)
'name' => $handle->file_dst_pathname,
];
Imgs::setWater($handle->file_dst_pathname, $arr);
}
break;
default:
echo $handle->error;
break;
}
}
// 图片完整相对路径:/i/2021/05/03/k88e7p.jpg
if ($handle->processed) {
header('Content-type:text/json');
// 上传成功后返回json数据
$imageUrl = $config['imgurl'] . config_path() . $handle->file_dst_name;
// 判断PHP版本启用删除
$ver = substr(PHP_VERSION, 0, 3);
if ($ver >= '7.0') {
$delUrl = $config['domain'] . '/api/del.php?hash=' . urlHash(config_path() . $handle->file_dst_name, 0);
} else {
$delUrl = 'PHP≥7.0 才能启用删除!';
}
$reJson = array(
"result" => 'success',
"url" => $imageUrl,
"del" => $delUrl,
);
echo json_encode($reJson);
$handle->clean();
} else {
// 上传错误 返回错误信息
$reJson = array(
"result" => 'failed',
"message" => $handle->error,
);
echo json_encode($reJson, JSON_UNESCAPED_UNICODE);
}
// 压缩图片 后压缩模式,不影响前台输出速度
if (!isAnimatedGif($handle->file_dst_pathname))
if ($config['compress']) {
require 'libs/compress/Imagick/class.Imgcompress.php';
$img = new Imgcompress($handle->file_dst_pathname, 1);
$img->compressImg($handle->file_dst_pathname);
// 释放
ob_flush();
flush();
}
unset($handle);
}