From 7713f704c6103559e61c162331396e3b6776c0de Mon Sep 17 00:00:00 2001 From: xiaoz Date: Wed, 13 Mar 2019 18:58:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=89=B9=E9=87=8F=E5=8E=8B?= =?UTF-8?q?=E7=BC=A9=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 10 +++++-- data/scripts/compress.py | 63 ++++++++++++++++++++++++++++++++++++++++ data/version.txt | 2 +- 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 data/scripts/compress.py diff --git a/README.md b/README.md index 311f0d2..82f6c8d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ImgURL -ImgURL是一款简单、好用的图床程序,使用PHP + SQLite 3开发,不需要复杂的配置,开箱即用。 +ImgURL是一款简单、纯粹的图床程序,使用PHP + SQLite 3开发。 ![](https://i.bmp.ovh/imgs/2018/12/06cf0ac3b7625b6b.png) @@ -24,7 +24,8 @@ ImgURL是一款简单、好用的图床程序,使用PHP + SQLite 3开发,不 * pathinfo ### 安装 -请参考帮助文档:[https://doc.xiaoz.me/](https://doc.xiaoz.me/#/imgurl2/) +* 常规安装请参考帮助文档:[https://doc.xiaoz.me/](https://doc.xiaoz.me/#/imgurl2/) +* 宝塔面板安装ImgURL参考:[https://www.xiaoz.me/archives/12081](https://www.xiaoz.me/archives/12081) ### Demo * [http://test.imgurl.org/](http://test.imgurl.org/) @@ -35,11 +36,16 @@ ImgURL是一款简单、好用的图床程序,使用PHP + SQLite 3开发,不 ![](https://www.xiaoz.me/wp-content/uploads/2013/12/juanzeng260.png) ### 鸣谢 + +ImgURL的诞生离不开以下项目,在此表示感谢。 + * [LayUI](https://github.com/sentsin/layui) * [CodeIgniter](https://github.com/bcit-ci/CodeIgniter) * [clipBoard.js](https://github.com/baixuexiyang/clipBoard.js) * [Parsedown](https://github.com/erusev/parsedown) * [jQuery](https://github.com/jquery/jquery) +* [tinypng](https://tinypng.com/) +* [ModerateContent](https://www.moderatecontent.com/) ### 联系我 * Blog:[https://www.xiaoz.me/](https://www.xiaoz.me/) diff --git a/data/scripts/compress.py b/data/scripts/compress.py new file mode 100644 index 0000000..3e47087 --- /dev/null +++ b/data/scripts/compress.py @@ -0,0 +1,63 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +##### name: 图片批量压缩 ##### +##### author: xiaoz.me ##### +##### update: 2018-03-13 ##### + +import sqlite3 +import os + + +#图片根目录 +global imgpath +#设置图片绝对路径 +imgpath = '/data/wwwroot/test.imgurl.org' +conn = sqlite3.connect(imgpath + "/data/imgurl.db3") + + +c = conn.cursor() +#查询10张没有压缩的图片 +imgs = c.execute("SELECT a.path,a.compression,b.mime,b.ext,a.id FROM img_images AS a INNER JOIN img_imginfo b ON a.imgid = b.imgid AND a.compression = 0 ORDER BY a.id DESC LIMIT 10") + +#更新图片状态,compression标记为1,标识已经压缩 +def upimg(imgid): + u = conn.cursor() + #更新数据库 + upimg = u.execute("UPDATE img_images SET compression = 1 WHERE `id` = " + str(imgid)) + conn.commit() + +#压缩图片的函数 +def compress(mime,path,imgid): + #图片完整路径 + fullpath = imgpath + path + #图片大小 + imgsize = os.path.getsize(fullpath) + #如果图片大于100K就进行压缩 + if imgsize >= 102400: + if mime == 'image/jpeg': + #优化图片 + os.system('jpegoptim -m 80 ' + fullpath) + #更新数据库 + upimg(imgid) + print(path + "已优化!\n") + elif mime == 'image/png' or mime == 'image/bmp': + #优化图片 + os.system('optipng ' + fullpath) + #更新数据库 + upimg(imgid) + print(path + "已优化!\n") + else: + skip = c.execute("UPDATE img_images SET compression = -1 WHERE `id` = " + str(imgid)) + print("当前没有需要处理的图片!\n") + conn.commit() + else: + print("图片不足100k,跳过!\n") + skip = conn.execute("UPDATE img_images SET compression = -1 WHERE `id` = " + str(imgid)) + conn.commit() + +#遍历输出 +for row in imgs: + compress(row[2],row[0],row[4]) + +#关闭数据库连接 +conn.close() diff --git a/data/version.txt b/data/version.txt index 9a3a1d3..d4ae8ab 100644 --- a/data/version.txt +++ b/data/version.txt @@ -1 +1 @@ -v2.0-20190110 \ No newline at end of file +v2.01-20190313 \ No newline at end of file