diff --git a/.vscode/launch.json b/.vscode/launch.json deleted file mode 100644 index dc9987f..0000000 --- a/.vscode/launch.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - // 使用 IntelliSense 了解相关属性。 - // 悬停以查看现有属性的描述。 - // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 - "version": "0.2.0", - "configurations": [ - { - "name": "Listen for XDebug", - "type": "php", - "request": "launch", - "port": 9999 - }, - { - "name": "Launch currently open script", - "type": "php", - "request": "launch", - "program": "${file}", - "cwd": "${fileDirname}", - "port": 9999 - } - ] -} \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..cfbc66d --- /dev/null +++ b/LICENSE @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. \ No newline at end of file diff --git a/README.md b/README.md index 2e6f9f2..eba256a 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,39 @@ +#### 首页演示: ![简单图床示例](https://img.545141.com/public/data/2019/05/5ce6915f50a1a.png "简单图床示例") -![简单图床示例](https://img.545141.com/public/data/2019/05/5ce6b41416a2b.png "简单图床示例") +#### 管理界面演示: +![简单图床示例](https://img.545141.com/public/data/2019/05/5cecf12575f6e.png "简单图床示例") ## EasyImage 简单图床 -> 支持多文件上传,异地上传,api上传,简单无数据库,返回图片url,markdown,bbscode,html的一款图床程序 -演示地址: [https://img.545141.com](https://img.545141.com"https://img.545141.com") -之前一直用的图床程序是:[PHP多图长传程序2.4.3](http://www.mycodes.net/48/4925.htm "PHP多图长传程序2.4.3") +> 支持多文件上传,异地上传,api上传,简单无数据库,返回图片url,markdown,bbscode,html的一款自适应图床程序 +演示地址:[https://img.545141.com](https://img.545141.com "PHP多图片上传程序 2.4.3") +之前一直用的图床程序是:[PHP多图片上传程序 2.4.3](http://www.mycodes.net/48/4925.htm "PHP多图片上传程序 2.4.3") 由于版本过老并且使用falsh上传,在当前html5流行大势所趋下,遂利用基础知识新写了一个以html5为默认上传并且支持flash,向下兼容至IE9。 +#### 功能支持: +- [x] 支持仅登录后上传 +- [x] 支持设置图片质量 +- [x] 支持QQ截图,剪切板上传 +- [x] 支持在线管理(增删改查) +- [x] 支持上传图片转换为指定格式 +- [x] 支持文字/图片水印 文字/图片水印透明度 +- [x] 支持压缩图片并自定义图片质量,相比之前提高5倍以上 +- [x] 支持设置上传页面广告 +- [x] 支持设置图片指定宽/高 +- [x] 支持最低上传宽度/高度 +- [x] 支持开启/关闭api上传(默认关闭) +- [x] 支持上传图片至远程服务器(异域存储,默认关闭) +- [x] 支持网站统计 请将统计代码放入:public/static/hm.js + 注意: - 1. 装之前先使用服务器打开check.php检查扩展是否都安装! -2. js不要设置分片上传大小,此会导致部分图片上传失败。 -3. 使用前请注意先修改config.php中的domain域名。 -4. 安装正常后请修改登录上传密码和管理密码!具体如何修改可以打开config.php里边有注释。 -5. 如果无法登陆管理界面或上传图片,请先打开check.php检查扩展。 -6. 默认我会给你设置成最优方案,如果需要其他的功能,比如异地存储和api上传,请仔细查看config.php文件 - - -##### 一年未更新了,这次带来了全新版本2.0! -- 在继承上个版本(1.6.4)的基础上进行了全新优化 -- 修复上传经常失败的问题 -- 删除一些不常用但会增加功耗的过程 (删除的在下边会有标记) -- 全新的压缩 将文件继续缩小 -- 全新的目录系统,精简代码 -- 设置仅允许在config.php修改,注释更加明了,即使没有代码基础也可以操作 -- 增加新的文件管理系统 +2. 使用前请注意先修改config.php中的domain域名。 +3. 安装正常后请修改登录上传密码和管理密码!具体如何修改可以打开config.php里边有注释。 +4. 如果无法登陆管理界面或上传图片,请先打开check.php检查扩展或者使用phpinfo检查。 +5. 默认我会给你设置成最优方案,api与异域上传默认关闭,如需要异地存储和api上传,请仔细查看教程。 +6. 下载源码后可以精简一些文件:README.md,check.php,LICENSE如不需要异域存储,可以删除crossdomain文件夹。
-#### 功能支持: - -- 支持设置图片质量 -- 支持上传图片转换为指定格式 -- 支持设置图片指定宽/高 -- 支持限制最低宽度/高度上传 -- 支持静态文件CDN/本地切换 -- ~~支持开启/关闭浏览最近上传图片~~ -> 使用最新的管理系统 -- 支持仅登录后上传 -- 支持设置广告 -- 支持网站统计 请将统计代码放入:public/static/hm.js -- 图片管理(删除,查看) -- 支持上传图片至远程服务器(异域存储) -- 支持开启/关闭api上传 - #### api上传示例: 参数: @@ -84,65 +75,82 @@ header('Access-Control-Allow-Origin:https://A.com/') 指定域名可以限制别人上传图片!(并不能保证完全能防止,毕竟可以伪造) --- -* 2019-5-23 v2.0 + 2019-5-31 v2.0.1.9 +- 增加复制链接按钮 +- 恢复开启/关闭api上传 +- 恢复支持水印文字颜色 +- 恢复支持远程上传图片 +- 增加QQ截图,剪切板上传 +- 增加文字/图片水印透明度 +- 纪念一下2019年,将版本号改为2.0.1.9 +- 修改图片压缩方式,速度更快,相比之前提高5倍以上 +- 修复在centos64 lnmp1.6 php7.1环境下的图片信息读取问题 +- 修复安装时候的权限 +- 更改管理路径 +- 更改上传路径,文件名更短 +- 添加暂停按钮 + + + 2019-5-23 v2.0 - 在继承上个版本(1.6.4)的基础上进行了全新优化 - 修复上传经常失败的问题 - 删除一些不常用但会增加功耗的过程 - 全新的压缩 将文件继续缩小 - 全新的目录系统,精简代码 - 设置仅允许在config.php修改,注释更加明了,即使没有代码基础也可以操作 -- 增加新的文件管理系统,感谢 tinyfilemanager -- ~~支持文字/图片水印 可自定义文字颜色~~ +- 增加新的文件管理系统,支持增删改查 +- ~~支持删除远程上传文件~~ +- 支持文字/图片水印 可自定义文字颜色~~ - ~~支持文字水印背景颜色~~ - ~~支持文字水印透明度~~ -- ~~支持删除远程上传文件~~ -> 不再支持删除远程文件 - ~~(支持开启/关闭api自定义文字水印)~~ - ~~支持删除自定义删除图片(仅管理员)~~ -* 2018-8-17 v1.6.4 + 2018-8-17 v1.6.4 - 支持删除远程上传文件 - 更改字体 - 添加api/远程上传 标识 -* 2018-8-16 v1.6.3 + + 2018-8-16 v1.6.3 - 支持开启/关闭api上传(支持开启/关闭api自定义文字水印) - 修复权限错误 - 修复二级目录引入错误 -* 2018-8-8 v1.5.3 + 2018-8-8 v1.5.3 - 添加上传图片至远程主机 - 修复逻辑 -* 2018-8-6 v1.4.3 + 2018-8-6 v1.4.3 - 添加网站统计 - 添加删除上传文件 - 调整config.php -* 2018-8-5 v1.4.2 + 2018-8-5 v1.4.2 - 添加仅登录后上传 - 修复一处逻辑错误 - 修复一个漏洞 -* 2018-8-4 v1.3.2 + 2018-8-4 v1.3.2 - 添加广告设置 - 完善引入机制 -* 2018-8-3 v1.2.2 + 2018-8-3 v1.2.2 - [重要]修复水印图片不能添加 - 添加随机浏览上传图片 可以设定浏览数量和关闭浏览 - 优化代码,删除无用文件 - 完善一键CDN静态文件 -* 2018-08-02 v1.1.2 + 2018-08-02 v1.1.2 - [重要] 修复gif上传添加水印成静态的问题 - 修复文字水印背景色不显示问题 - 修复在linux下的权限错误 - 一些优化更改 -* 2018-08-01 v1.0.1 + 2018-08-01 v1.0.1 - 更改相关文件目录 - 优化代码 -* 2018-07-30 v1.0.0 + 2018-07-30 v1.0.0 - 最初模型 #### 兼容性 @@ -154,4 +162,4 @@ header('Access-Control-Allow-Origin:https://A.com/') - 感谢: [verot](https://www.verot.net "verot" )提供非常好用的class.upload.php上传类 - 感谢: [ZUI](http://zui.sexy/ "ZUI" ) 提供css框架 - 感谢:[tinyfilemanager](https://github.com/prasathmani/tinyfilemanager "tinyfilemanager" ) 提供的文件管理 - - 本源码遵循 GNU Public License \ No newline at end of file + - 本源码遵循 GNU Public License diff --git a/check.php b/check.php index 98bd8d9..24f5176 100644 --- a/check.php +++ b/check.php @@ -36,6 +36,12 @@
新加密密码:'.password_hash($_POST['psw'],PASSWORD_DEFAULT).''; + echo '
请将新密码全部复制并覆盖/public/data/tinyfilemanager.php第28行中替换相应的字符'; + echo '
登录密码为:'.$_POST['psw'].''; +} + echo '
当前PHP版本:'.phpversion(); if(extension_loaded('gd')){ echo '
GD已安装:'.gd_info()['GD Version']; @@ -73,12 +79,6 @@ if(!extension_loaded('mbstring')){ echo '
mbstring已安装'; } - -if(@isset($_POST['psw'])){ - echo '

新加密密码:'.password_hash($_POST['psw'],PASSWORD_DEFAULT).''; - echo '
请将新密码全部复制并覆盖/public/data/tinyfilemanager.php第28行中替换相应的字符'; - echo '
登录密码为:'.$_POST['psw'].''; -} echo '

以下是php所有拓展和版本信息,请使用ctrl+f快速搜索查找问题:
'; phpinfo(); exit; \ No newline at end of file diff --git a/config.php b/config.php index c42b451..418c3c2 100644 --- a/config.php +++ b/config.php @@ -1,6 +1,6 @@ '简单图床 - EasyImage', // 网站关键字 - 'keywords' => '简单图床,easyimage,无数据库图床', + 'keywords' => '简单图床,easyimage,无数据库图床,PHP多图长传程序,自适应页面,HTML5,markdown,bbscode,一键复制', // 网站描述 - 'description' => '支持多文件上传,远程上传,api上传,简单无数据库,直接返回图片url,markdown,bbscode的一款html5图床程序 。', + 'description' => '简单图床EasyImage是一款支持多文件上传的无数据库图床,可以完美替代PHP多图上传程序,最新html5自适应页面兼容手机电脑,上传后返回图片直链,markdown图片,论坛贴图bbscode链接,简单方便支持一键复制,支持多域名,api上传。', // 网站公告 - 'tips' => ' 单个文件限制5M,每次最多上传30张图片。', + 'tips' => ' 单个文件限制5M,每次最多上传30张图片,本网站仅做演示用,不对图片负任何责任。', // 当前域名,末尾不加"/" 如果是异域上传请修改为当前异域域名 'domain' => 'https://img.545141.com', - // 存储路径 末尾需要加"/" - 'path' => '/public/data/', + // 存储路径 前后要加"/" 如更改此目录,需要修改tinyfilemanager.php中的$directories_users路径 + 'path' => '/i/', // 最大上传限制 默认为5m 请使用工具转换mb http://www.bejson.com/convert/filesize/ 'maxSize' => 5242880, // 是否开启登录上传 开启:true 关闭false 'mustLogin' => false, - // 登录密码 此密码非管理密码 - 'password'=>'7070', + // 登录密码 此密码非管理密码 + 'password' => '7080', // 开启管理 开启后务必修改密码 修改方式请见read.php 'tinyfilemanager' => true, // 是否开启API上传 'apiStatus' => false, // 是否开启异域上传 开启true 关闭 false - 'crossdomain'=>false, - // 异域上传域名 末尾需要加'/' - 'CDomains'=>'https://img.545141.com/crossdomain/', + 'crossdomain' => false, + // 异域上传域名 末尾需要加'/' + 'CDomains' => 'https://img.545141.com/crossdomain/', // 是否开启水印:0关闭,1文字水印,2图片水印 动态gif不能添加水印 'watermark' => 1, // 水印文字内容 - 'waterText' => 'img.545141.com', - // 水印位置 T=top,B =bottom,L=left,R=right 'TBLR'中的一个或两个的组合 - 'waterPosition' => 'TB', - // 水印文字方向 h水平 v垂直 - 'textDirection' => 'h', - // 水印文字颜色 - 'textColor' => '#DC143C', + 'waterText' => '简单图床 img.545141.com', + /** + * 水印位置 + * 0:随机位置,在1~8之间随机选取一个位置 + * 1:顶部居左 2:顶部居中 3:顶部居右 4:左边居中 + * 5:图片中心 6:右边居中 7:底部居左 8:底部居中 9:底部居右 + */ + 'waterPosition' => 8, + // 水印文字颜色 rgba 末尾为透明度0-127 0为不透明 + 'textColor' => '47,79,79,0', // 水印文字大小 'textSize' => 16, - // 字体大小或字体的相对路径 - 'textFont' => APP_ROOT.'/public/static/imitationSong.ttf', - // 水印边距 px - 'textPadding' => 10, - // 水印透明度 - 'textOpacity' => 100, + // 字体路径 如果想改变字体,请选择支持中文的 gb2312 + 'textFont' => APP_ROOT . '/public/static/hkxzy.ttf', // 图片水印路径 支持GIF,JPG,BMP,PNG和PNG alpha 'waterImg' => 'public/static/watermark.png', // 转换图片为指定格式 可选:''|'png'|'jpeg'|'gif'|'bmp';默认值:'' 'imgConvert' => '', - // 设置PNG图像的压缩级别,介于1(快速但大文件)和9(慢速但较小的文件)之间 默认值:null - 'zipPNG' => null, - // 设置JPEG图像的压缩质量(默认值:85) - 'zipJPEG' => 85, - // 使用imagejpeg压缩 0为关闭输入值0-1,值越大质量越高 - 'jpg_zip_php'=>0.8, + // 是否通过缩放来压缩,如果要保持源图比例,把参数$percent保持为1,范围 0.1-1 + // 即使原比例压缩,也可大幅度缩小。如果缩小比例,则体积会更小。 + 'imgcompress_percent' => 0.95, //最大宽度 'maxWidth' => 10240, // 最大高度 'maxHeight' => 10240, - // 最小宽度 + // 允许上传的最小宽度 'minWidth' => 5, - // 最小高度 + // 允许上传的最小高度 'minHeight' => 5, // 等比例缩小图片 宽度和高度请设置 image_x image_y 开启true,关闭false 关闭下mage_x和image_y设置不生效 'imgRatio' => false, @@ -93,5 +89,5 @@ $config = array( 'ad_top' => false, // 开启底部广告 如果想添加或修改广告请到 public/static/ad_bot.html 'ad_bot' => false, - 'Version' => '2.0.0.9' -); \ No newline at end of file + 'Version' => '2.0.1.9', +); diff --git a/crossdomain/config.php b/crossdomain/config.php index 9467f66..c9ad1d4 100644 --- a/crossdomain/config.php +++ b/crossdomain/config.php @@ -1,6 +1,6 @@ 'h', // 水印文字颜色 - 'textColor' => '#DC143C', + 'textColor' => '#778899', // 水印文字大小 'textSize' => 16, - // 字体大小或字体的相对路径 - 'textFont' => APP_ROOT.'/public/static/imitationSong.ttf', + // 字体路径 如果想改变字体,请选择支持中文的 gb2312 + 'textFont' => APP_ROOT.'/public/static/hkxzy.ttf', // 水印边距 px 'textPadding' => 10, // 水印透明度 @@ -67,12 +67,9 @@ $config = array( 'waterImg' => 'public/static/watermark.png', // 转换图片为指定格式 可选:''|'png'|'jpeg'|'gif'|'bmp';默认值:'' 'imgConvert' => '', - // 设置PNG图像的压缩级别,介于1(快速但大文件)和9(慢速但较小的文件)之间 默认值:null - 'zipPNG' => null, - // 设置JPEG图像的压缩质量(默认值:85) - 'zipJPEG' => 85, - // 使用imagejpeg压缩 0为关闭输入值0-1,值越大质量越高 - 'jpg_zip_php'=>0.8, + // 是否通过缩放来压缩,如果要保持源图比例,把参数$percent保持为1,范围 0.1-1 + // 即使原比例压缩,也可大幅度缩小。如果缩小比例,则体积会更小。 + 'imgcompress_percent' => 0.9, //最大宽度 'maxWidth' => 10240, // 最大高度 diff --git a/crossdomain/file.php b/crossdomain/file.php index f20e850..1ffb0db 100644 --- a/crossdomain/file.php +++ b/crossdomain/file.php @@ -24,10 +24,6 @@ if($handle->uploaded){ $handle->image_min_height = $config['minHeight']; // 转换图片为指定格式 $handle->image_convert = $config['imgConvert']; - //PNG图片压缩 - $handle->png_compression = $config['zipPNG']; - //JPEG图片压缩 - $handle->jpeg_quality = $config['zipJPEG']; //等比例缩减图片 if($config['imgRatio']){ @@ -86,19 +82,13 @@ if($handle->uploaded){ echo $handle->error; } - if($config['jpg_zip_php']>0 && $handle->file_dst_name_ext=='jpg'){ - $file = __DIR__.config_path().$handle->file_dst_name; - $percent = $config['jpg_zip_php']; //图片压缩比 - list($width, $height) = getimagesize($file); //获取原图尺寸 - //缩放尺寸 - $newwidth = $width * $percent; - $newheight = $height * $percent; - $src_im = imagecreatefromjpeg($file); - $dst_im = imagecreatetruecolor($newwidth, $newheight); - imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); - imagejpeg($dst_im,$file); //输出压缩后的图片 - imagedestroy($dst_im); - imagedestroy($src_im); + // 上传完成图片后调用imgcompress类压缩图片 + if($config['imgcompress_percent']>0 && $handle->file_dst_name_ext!='gif'){ + $source = APP_ROOT.config_path().$handle->file_dst_name; // 原图 + $dst_img = APP_ROOT.config_path().$handle->file_dst_name; //存放路径 + $percent = $config['imgcompress_percent']; #是否缩放压缩 + $image = (new imgcompress($source,$percent))->compressImg($dst_img); } + unset($handle); } \ No newline at end of file diff --git a/crossdomain/libs/imgcompress.php b/crossdomain/libs/imgcompress.php new file mode 100644 index 0000000..6aa9cbc --- /dev/null +++ b/crossdomain/libs/imgcompress.php @@ -0,0 +1,130 @@ +src = $src; + $this->percent = $percent; + } + + + /** 高清压缩图片 + * @param string $saveName 提供图片名(可不带扩展名,用源图扩展名)用于保存。或不提供文件名直接显示 + */ + public function compressImg($saveName='') + { + $this->_openImage(); + if(!empty($saveName)) $this->_saveImage($saveName); //保存 + else $this->_showImage(); + } + + /** + * 内部:打开图片 + */ + private function _openImage() + { + list($width, $height, $type, $attr) = getimagesize($this->src); + $this->imageinfo = array( + 'width'=>$width, + 'height'=>$height, + 'type'=>image_type_to_extension($type,false), + 'attr'=>$attr + ); + $fun = "imagecreatefrom".$this->imageinfo['type']; + $this->image = $fun($this->src); + $this->_thumpImage(); + } + /** + * 内部:操作图片 + */ + private function _thumpImage() + { + $new_width = $this->imageinfo['width'] * $this->percent; + $new_height = $this->imageinfo['height'] * $this->percent; + $image_thump = imagecreatetruecolor($new_width,$new_height); + //将原图复制带图片载体上面,并且按照一定比例压缩,极大的保持了清晰度 + imagecopyresampled($image_thump,$this->image,0,0,0,0,$new_width,$new_height,$this->imageinfo['width'],$this->imageinfo['height']); + imagedestroy($this->image); + $this->image = $image_thump; + } + /** + * 输出图片:保存图片则用saveImage() + */ + private function _showImage() + { + header('Content-Type: image/'.$this->imageinfo['type']); + $funcs = "image".$this->imageinfo['type']; + $funcs($this->image); + } + /** + * 保存图片到硬盘: + * @param string $dstImgName 1、可指定字符串不带后缀的名称,使用源图扩展名 。2、直接指定目标图片名带扩展名。 + */ + private function _saveImage($dstImgName) + { + if(empty($dstImgName)) return false; + $allowImgs = ['.jpg', '.jpeg', '.png', '.bmp', '.wbmp','.gif']; //如果目标图片名有后缀就用目标图片扩展名 后缀,如果没有,则用源图的扩展名 + $dstExt = strrchr($dstImgName ,"."); + $sourseExt = strrchr($this->src ,"."); + if(!empty($dstExt)) $dstExt =strtolower($dstExt); + if(!empty($sourseExt)) $sourseExt =strtolower($sourseExt); + + //有指定目标名扩展名 + if(!empty($dstExt) && in_array($dstExt,$allowImgs)){ + $dstName = $dstImgName; + }elseif(!empty($sourseExt) && in_array($sourseExt,$allowImgs)){ + $dstName = $dstImgName.$sourseExt; + }else{ + $dstName = $dstImgName.$this->imageinfo['type']; + } + $funcs = "image".$this->imageinfo['type']; + $funcs($this->image,$dstName); + } + + /** + * 销毁图片 + */ + public function __destruct(){ + imagedestroy($this->image); + } + +} + +/* 调用方法 +$source = '1.jpg; // 原图 +$dst_img = '2.jpg'; //可加存放路径 +$percent = 1; #原图压缩,不缩放 +$image = (new imgcompress($source,$percent))->compressImg($dst_img); +------------------------------------------------------------------------ +// 原压缩设置,其实就是提取了上面类中的精华 + + $file = __DIR__.config_path().$handle->file_dst_name; + $percent = $config['jpg_zip_php']; //图片压缩比 + list($width, $height) = getimagesize($file); //获取原图尺寸 + //缩放尺寸 + $newwidth = $width * $percent; + $newheight = $height * $percent; + $src_im = imagecreatefromjpeg($file); + $dst_im = imagecreatetruecolor($newwidth, $newheight); + imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); + imagejpeg($dst_im,$file); //输出压缩后的图片 + imagedestroy($dst_im); + imagedestroy($src_im); + */ \ No newline at end of file diff --git a/crossdomain/public/static/hkxzy.ttf b/crossdomain/public/static/hkxzy.ttf new file mode 100644 index 0000000..f892d2f Binary files /dev/null and b/crossdomain/public/static/hkxzy.ttf differ diff --git a/crossdomain/public/static/imitationSong.ttf b/crossdomain/public/static/imitationSong.ttf deleted file mode 100644 index 16eb427..0000000 Binary files a/crossdomain/public/static/imitationSong.ttf and /dev/null differ diff --git a/crossdomain/public/static/zui/fonts/zenicon.ttf b/crossdomain/public/static/zui/fonts/zenicon.ttf deleted file mode 100644 index 0d3d5e0..0000000 Binary files a/crossdomain/public/static/zui/fonts/zenicon.ttf and /dev/null differ diff --git a/favicon.ico b/favicon.ico deleted file mode 100644 index 5ed838b..0000000 Binary files a/favicon.ico and /dev/null differ diff --git a/file.php b/file.php index 390c2ac..c93f971 100644 --- a/file.php +++ b/file.php @@ -1,17 +1,18 @@ uploaded){ +if ($handle->uploaded) { // 允许上传的mime类型 - $handle->allowed = array ('image/*'); + $handle->allowed = array('image/*'); // 文件命名 - $handle->file_new_name_body = uniqid(); + $handle->file_new_name_body = imgName(); // 最大上传限制 $handle->file_max_sizes = $config['maxSize']; // 最大宽度 @@ -21,40 +22,47 @@ if($handle->uploaded){ // 最小宽度 $handle->image_min_width = $config['minWidth']; // 最小高度 - $handle->image_min_height = $config['minHeight']; + $handle->image_min_height = $config['minHeight']; // 转换图片为指定格式 $handle->image_convert = $config['imgConvert']; - //PNG图片压缩 - $handle->png_compression = $config['zipPNG']; - //JPEG图片压缩 - $handle->jpeg_quality = $config['zipJPEG']; - + //等比例缩减图片 - if($config['imgRatio']){ + if ($config['imgRatio']) { $handle->image_x = $config['image_x']; } + // 存储图片路径:images/201807/ + $handle->process(APP_ROOT . config_path()); // 设置水印 - if ($config['watermark'] > 0){ - switch ($config['watermark']){ + if ($config['watermark'] > 0) { + switch ($config['watermark']) { case 1: // 文字水印 过滤gif - if (isAnimatedGif($handle->file_src_pathname)===0){ - $handle->image_text = $config['waterText']; - $handle->image_text_direction = $config['textDirection']; - $handle->image_text_color = $config['textColor']; - $handle->image_text_opacity = $config['textOpacity']; - $handle->image_text_font = $config['textFont']; - $handle->image_text_size = $config['textSize']; - $handle->image_text_padding = $config['textPadding']; - $handle->image_text_position = $config['waterPosition']; + 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){ - $handle->image_watermark = $config['waterImg']; - $handle->image_watermark_position = $config['waterPosition']; - $handle->image_watermark_no_zoom_in = true; - $handle->image_watermark_no_zoom_out = true; + 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: @@ -63,42 +71,64 @@ if($handle->uploaded){ } } - // 存储图片路径:images/201807/ - $handle->process(APP_ROOT.config_path()); - // 图片完整相对路径:images/201807/0ed7ccfd4dab9cbc.jpg - if ($handle->processed){ + if ($handle->processed) { header('Content-type:text/json'); // 上传成功后返回json数据 - $reJson = array ( - "result" => 'success', - "url" => $config['domain'].config_path().$handle->file_dst_name, - ); - echo json_encode($reJson); - $handle->clean(); - }else{ - // 上传错误 返回错误信息 - $reJson = array ( - "result" => 'failed', - "message" => $handle->error + $reJson = array( + "result" => 'success', + "url" => $config['domain'] . config_path() . $handle->file_dst_name, ); echo json_encode($reJson); - echo $handle->error; + $handle->clean(); + } else { + // 上传错误 返回错误信息 + $reJson = array( + "result" => 'failed', + "message" => $handle->error, + ); + echo json_encode($reJson,JSON_UNESCAPED_UNICODE); } - - if($config['jpg_zip_php']>0 && $handle->file_dst_name_ext=='jpg'){ - $file = __DIR__.config_path().$handle->file_dst_name; - $percent = $config['jpg_zip_php']; //图片压缩比 - list($width, $height) = getimagesize($file); //获取原图尺寸 + + // 利用 imagecreatefrom*压缩不太好用,不过可以预防病毒 + if ($config['imgcompress_percent'] > 0 && $handle->file_dst_name_ext != 'gif') { + $percent = $config['imgcompress_percent']; //图片压缩比 + list($width, $height) = getimagesize($handle->file_dst_pathname); //获取原图尺寸 //缩放尺寸 $newwidth = $width * $percent; $newheight = $height * $percent; - $src_im = imagecreatefromjpeg($file); - $dst_im = imagecreatetruecolor($newwidth, $newheight); - imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); - imagejpeg($dst_im,$file); //输出压缩后的图片 - imagedestroy($dst_im); - imagedestroy($src_im); + + if ($handle->file_dst_name_ext === 'jpg') { + $src_im = imagecreatefromjpeg($handle->file_dst_pathname); + $dst_im = imagecreatetruecolor($newwidth, $newheight); + imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); + imagejpeg($dst_im, $handle->file_dst_pathname); //输出压缩后的图片 + imagedestroy($dst_im); + imagedestroy($src_im); + } elseif ($handle->file_dst_name_ext === 'png') { + $src_im = imagecreatefrompng($handle->file_dst_pathname); + $dst_im = imagecreatetruecolor($newwidth, $newheight); + imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); + imagepng($dst_im, $handle->file_dst_pathname); //输出压缩后的图片 + imagedestroy($dst_im); + imagedestroy($src_im); + } elseif ($handle->file_dst_name_ext === 'gif') { + $src_im = imagecreatefromgif($handle->file_dst_pathname); + $dst_im = imagecreatetruecolor($newwidth, $newheight); + imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); + imagegif($dst_im, $handle->file_dst_pathname); //输出压缩后的图片 + imagedestroy($dst_im); + imagedestroy($src_im); + } elseif ($handle->file_dst_name_ext === 'wbmp') { + $src_im = imagecreatefromwbmp($handle->file_dst_pathname); + $dst_im = imagecreatetruecolor($newwidth, $newheight); + imagecopyresized($dst_im, $src_im, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); + imagewbmp($dst_im, $handle->file_dst_pathname); //输出压缩后的图片 + imagedestroy($dst_im); + imagedestroy($src_im); + } + } + unset($handle); } \ No newline at end of file diff --git a/i/Default upload folder b/i/Default upload folder new file mode 100644 index 0000000..e69de29 diff --git a/index.php b/index.php index a5810e0..abc9cfe 100644 --- a/index.php +++ b/index.php @@ -16,13 +16,15 @@ if (@$_GET['e']==1){
-
+
+
@@ -36,18 +38,28 @@ if (@$_GET['e']==1){
  • HTML
  • -
    +
    - + +
    -
    
    +            
    +            
               
    -
    
    +            
    +            
               
    -
    
    +            
    +            
               
    @@ -73,7 +85,7 @@ if (@$_GET['e']==1){ filters: { // 只允许上传图片或图标(.ico) mime_types: [{ title: '图片', - extensions: 'bmp,jpg,png,tif,gif,pcx,tga,svg,webp' + extensions: 'bmp,jpg,png,tif,gif,pcx,tga,svg,webp,jpeg,tga,svg,webp,ico' }, { title: '图标', @@ -93,20 +105,19 @@ if (@$_GET['e']==1){ console.log(responseObject.response); var obj = JSON.parse(responseObject.response); //由JSON字符串转换为JSON对象 var links = document.getElementById("links"); - links.innerHTML += obj.url + "
    "; + links.innerHTML += obj.url + "\n"; var bbscode = document.getElementById("bbscode"); - bbscode.innerHTML += "[img]" + obj.url + "[/img]
    "; + bbscode.innerHTML += "[img]" + obj.url + "[/img]\n"; var markdown = document.getElementById("markdown"); - markdown.innerHTML += "![](" + obj.url + ")
    "; + markdown.innerHTML += "![](" + obj.url + ")\n"; var html = document.getElementById("html"); - html.innerHTML += "<img src=\"" + obj.url + "\" />
    "; + html.innerHTML += "<img src=\"" + obj.url + "\" />\n"; } else { return '上传失败。服务器返回了一个错误:' + responseObject.response; } - } }); diff --git a/libs/WaterMask.php b/libs/WaterMask.php new file mode 100644 index 0000000..1531168 --- /dev/null +++ b/libs/WaterMask.php @@ -0,0 +1,310 @@ + false, 'msg' => '请指定$src'); + } + + $temp = pathinfo($src); + # 文件名 + $name = $temp["basename"]; + # 文件所在的文件夹 + $dir = $temp["dirname"]; + # 文件扩展名 + $extension = $temp["extension"]; + # 缩略图保存路径,新的文件名为*.thumb.jpg + $savepath = "{$dir}/thumb_{$name}"; + + # 获取图片的基本信息 + $info = getimagesize($src); + # 获取图片宽度 + $width = $info[0]; + # 获取图片高度 + $height = $info[1]; + if (!empty($w)) { + $temp_w = $w; # 计算原图缩放后的宽度 + $temp_h = intval($height * ($w / $width)); # 计算原图缩放后的高度 + } else { + $temp_w = intval($width * ($h / $height)); # 计算原图缩放后的宽度 + $temp_h = $h; # 计算原图缩放后的高度 + } + + # 创建画布 + $temp_img = imagecreatetruecolor($temp_w, $temp_h); + switch ($info[2]) { + case 1: + $im = imagecreatefromgif($src); + imagecopyresampled($temp_img, $im, 0, 0, 0, 0, $temp_w, $temp_h, $width, $height); + imagegif($temp_img, $savepath, 100); + break; + case 2: + $im = imagecreatefromjpeg($src); + imagecopyresampled($temp_img, $im, 0, 0, 0, 0, $temp_w, $temp_h, $width, $height); + imagejpeg($temp_img, $savepath, 100); + break; + case 3: + $im = imagecreatefrompng($src); + imagecopyresampled($temp_img, $im, 0, 0, 0, 0, $temp_w, $temp_h, $width, $height); + imagepng($temp_img, $savepath, 100); + break; + } + imagedestroy($im); + return $savepath; + } + + /** + * 图片添加水印 + * @param string $src 1、图片相对路径或绝对路径 2、以逗号隔开的宽高值('800,600') + * @param array 属性值: + * res:水印资源(1、图片相对路径或绝对路径,2、字符串) + * pos:图片水印添加的位置,取值范围:0~9 + * 0:随机位置,在1~8之间随机选取一个位置 + * 1:顶部居左 2:顶部居中 + * 3:顶部居右 4:左边居中 + * 5:图片中心 6:右边居中 + * 7:底部居左 8:底部居中 + * 9:底部居右 + * font: 字体库(相对路径或绝对路径) + * fontSize:文字大小 + * color: 水印文字的字体颜色(255,255,255) + * name: 图片保存名称 + * @return array code:状态、 msg:提示信息、 url:图片地址 + **/ + public static function setWater($src, $arr = array()) + { + if (empty($src)) { + return array('code' => false, 'msg' => '请指定$src'); + } + + $def = array( + 'res' => '小川编程', + 'pos' => 7, + 'font' => './1.ttf', + 'fontSize' => 24, + 'color' => '255,255,255,0', + 'name' => null, + ); + $def = array_merge($def, $arr); + /** + 判断$src是不是图片,不是就创建画布 + */ + if (!file_exists($src)) { + if (empty($def['name'])) { + return array('code' => false, 'msg' => '请指定图片名称'); + } + + # 计算画布宽高 + $obj = explode(',', $src); + if (count($obj) != 2) { + return array('code' => false, + 'msg' => '请给正确的宽高,或你给的不是一个有效的地址!'); + } + + $srcImg_w = is_numeric($obj[0]) ? $obj[0] : 400; + $srcImg_h = is_numeric($obj[1]) ? $obj[1] : 300; + # 创建画布 + $dst_img = @imagecreatetruecolor($srcImg_w, $srcImg_h); + } else { + # 获取图片信息 + $srcInfo = @getimagesize($src); + $srcImg_w = $srcInfo[0]; + $srcImg_h = $srcInfo[1]; + if (empty($def['name'])) { + $def['name'] = $src; + } + + # 动态的把图片导入内存中 + switch ($srcInfo[2]) { + case 1: + $dst_img = imagecreatefromgif($src); + break; + + case 2: + $dst_img = imagecreatefromjpeg($src); + break; + + case 3: + $dst_img = imagecreatefrompng($src); + break; + + default: + return array('code' => false, 'msg' => '目标图片类型错误'); + exit; + } + } + /** + 计算出水印宽高 + */ + if (!file_exists($def['res'])) { + if (!file_exists($def['font'])) { + return array('code' => false, 'msg' => '字体库不存在'); + } + + $box = @imagettfbbox($def['fontSize'], 0, $def['font'], $def['res']); + $logow = max($box[2], $box[4]) - min($box[0], $box[6]); + $logoh = max($box[1], $box[3]) - min($box[5], $box[7]); + } else { + $resInfo = @getimagesize($def['res']); + $res_w = $resInfo[0]; + $res_h = $resInfo[1]; + if ($srcImg_w < $res_w || $srcImg_h < $res_h) { + return array('code' => false, 'msg' => '水印图片过大'); + } + + # 动态的把图片导入内存中 + switch ($resInfo[2]) { + case 1: + $markim = imagecreatefromgif($def['res']); + break; + + case 2: + $markim = imagecreatefromjpeg($def['res']); + break; + + case 3: + $markim = imagecreatefrompng($def['res']); + break; + + default: + return array('code' => false, 'msg' => '水印图片类型错误'); + exit; + } + $logow = $res_w; + $logoh = $res_h; + } + /** + 计算水印显示位置 + */ + if ($def['pos'] == 0) { + $def['pos'] = rand(1, 9); + } + + switch ($def['pos']) { + case 1: + $x = +10; + $y = +10 + $def['fontSize']; + break; + + case 2: + $x = ($srcImg_w - $logow) / 2; + $y = +10 + $def['fontSize']; + break; + + case 3: + $x = $srcImg_w - $logow - 10; + $y = +10 + $def['fontSize']; + break; + + case 4: + $x = +10; + $y = ($srcImg_h - $logoh) / 2 + $def['fontSize']; + break; + + case 5: + $x = ($srcImg_w - $logow) / 2; + $y = ($srcImg_h - $logoh) / 2 + $def['fontSize']; + break; + + case 6: + $x = $srcImg_w - $logow - 10; + $y = ($srcImg_h - $logoh) / 2 + $def['fontSize']; + break; + + case 7: + $x = +10; + $y = $srcImg_h - $logoh + $def['fontSize'] - 10; + break; + + case 8: + $x = ($srcImg_w - $logow) / 2; + $y = $srcImg_h - $logoh + $def['fontSize'] - 10; + break; + + case 9: + $x = $srcImg_w - $logow - 10; + $y = $srcImg_h - $logoh + $def['fontSize'] - 10; + break; + + default: + return array('code' => false, 'msg' => '水印位置不支持'); + exit; + } + /** + 把图片水印或文字水印,加到目标图片中 + */ + if (file_exists($def['res'])) { + imagecopy($dst_img, $markim, $x, $y, 0, 0, $logow, $logoh); + imagedestroy($markim); + } else { + $rgb = explode(',', $def['color']); + if (count($rgb) != 4) { + return array('code' => false, 'msg' => '请给正确的字体颜色'); + } + + if (!is_numeric($rgb[0]) || !is_numeric($rgb[1]) || !is_numeric($rgb[2]) || !is_numeric($rgb[3])) { + return array('code' => false, 'msg' => '请给正确的字体颜色'); + } + + if ($rgb[0] > 255 || $rgb[1] > 255 || $rgb[2] > 255 || $rgb[3] > 127) { + return array('code' => false, 'msg' => '请给正确的字体颜色'); + } + + $def['color'] = imagecolorallocatealpha($dst_img, $rgb[0], $rgb[1], $rgb[2], $rgb[3]); + imagettftext($dst_img, $def['fontSize'], 0, $x, + $y, $def['color'], $def['font'], $def['res']); + } + /** + 保存处理过的图片(有水印了的图片) + */ + $name = explode('.', $def['name']); + $num = count($name)-1; + switch (strtolower($name[$num])) { + case 'jpeg': + imagejpeg($dst_img, $def['name']); + break; + case 'jpg': + imagejpeg($dst_img, $def['name']); + break; + case 'png': + imagepng($dst_img, $def['name']); + break; + case 'gif': + imagegif($dst_img, $def['name']); + break; + default: + return array('code' => false, 'msg' => '保存图片类型有误'); + break; + } + # 销毁图片内存资源 + imagedestroy($dst_img); + return array('code' => true, 'msg' => '添加水印成功', 'url' => $def['name']); + } +} diff --git a/libs/footer.php b/libs/footer.php index 6846209..013fb14 100644 --- a/libs/footer.php +++ b/libs/footer.php @@ -31,11 +31,13 @@ echo ' } }); - + + +
    '.showAD('bot').'
    - Copyright © 2018-'. date('Y').' EasyImage Powered By icret Verson: '.$config['Version'].@$qqgroup.' + Copyright © 2018-'. date('Y').' EasyImage Powered By icret Verson: '.$config['Version'].@$qqgroup.'
    diff --git a/libs/function.php b/libs/function.php index f54b451..cd42795 100644 --- a/libs/function.php +++ b/libs/function.php @@ -40,30 +40,26 @@ function checkLogin() { } } -// 检查配置文件中目录是否存在是否可写 +// 检查配置文件中目录是否存在是否可写并创建相应目录 + function config_path(){ - global $config; - $real_path = APP_ROOT.$config['path']; - if(!is_dir($real_path)){ - mkdir($real_path,0777,true); - }elseif(!is_writable($real_path)){ - chmod($real_path,0777); - } - //创建年目录 - $real_path = $config['path'].date('Y'); - if(!is_dir($real_path)){ - mkdir($real_path,0777); - }elseif(!is_writable($real_path)){ - chmod($real_path,0777); - } - // 创建月目录 - $real_path = $real_path.'/'.date('m'); - if(!is_dir($real_path)){ - mkdir($real_path,0777); - }elseif(!is_writable($real_path)){ - chmod($real_path,0777); - } - return $real_path.'/'; + global $config; + $img_path = $config['path'].date('Y').'/'.date('m').'/'.date('d'); + + if (!is_dir($img_path)){ + mkdir($img_path,0755,true); + } + + if (!is_writable($img_path)){ + chmod($img_path,0755); + } + + return $img_path.'/'; +} + +// 图片重命名规则 +function imgName(){ + return base_convert(date('His').mt_rand(1024,10240),10,36); } // 设置广告 @@ -98,7 +94,8 @@ function static_cdn(){ - + + '; }else{ @@ -111,6 +108,7 @@ function static_cdn(){ + '; } } diff --git a/libs/header.php b/libs/header.php index 5445a83..b6fcfd3 100644 --- a/libs/header.php +++ b/libs/header.php @@ -10,7 +10,7 @@ echo ' - + '.static_cdn().'