diff --git a/manifest/.vscode/settings.json b/manifest/.vscode/settings.json new file mode 100644 index 0000000..2773c6d --- /dev/null +++ b/manifest/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Users\\Mashiro\\AppData\\Local\\Programs\\Python\\Python38\\python.exe" +} \ No newline at end of file diff --git a/manifest/README.md b/manifest/README.md new file mode 100644 index 0000000..2707dd6 --- /dev/null +++ b/manifest/README.md @@ -0,0 +1,38 @@ +封面图生成工具 +=== + +### 依赖 +Python3 +PIL (Pillow) + +### 安装依赖 +安装 Python: +安装 PIL: + +```bash +# Linix/Mac Terminal +pip install Pillow +# 如果也安装了 Python 2,需要指定 pip 版本: +pip3 install Pillow + +# Windows Powershell 或者 CMD +pip install Pillow +# 如果也安装了 Python 2,需要指定 pip 版本: +pip3 install Pillow +# 如果提示权限不足([WinError 5] Access is denied),请运行: +pip install Pillow --user +``` + +### 运行 +把图片文件放到 `gallary` 目录,Windows 可直接双击 main.py,或者和其他操作系统一样,在 Terminal、Powershell、CMD 中运行: + +```bash +# 切换到 main.py 所在目录: +cd /path/to/manifest/ +python main.py +# 如果也安装了 Python 2,需要指定 pip 版本: +python3 main.py +``` + +### TODO +自动删除过期文件、压缩图片、GitHub API push、release \ No newline at end of file diff --git a/manifest/gallary/AK-01.jpg b/manifest/gallary/AK-01.jpg new file mode 100644 index 0000000..1ad2ce5 Binary files /dev/null and b/manifest/gallary/AK-01.jpg differ diff --git a/manifest/gallary/AK-02.jpg b/manifest/gallary/AK-02.jpg new file mode 100644 index 0000000..45d4b94 Binary files /dev/null and b/manifest/gallary/AK-02.jpg differ diff --git a/manifest/gallary/AK-03.jpg b/manifest/gallary/AK-03.jpg new file mode 100644 index 0000000..4bd4f1a Binary files /dev/null and b/manifest/gallary/AK-03.jpg differ diff --git a/manifest/gallary/AK-04.jpg b/manifest/gallary/AK-04.jpg new file mode 100644 index 0000000..dacbd91 Binary files /dev/null and b/manifest/gallary/AK-04.jpg differ diff --git a/manifest/gallary/AK-05.jpg b/manifest/gallary/AK-05.jpg new file mode 100644 index 0000000..5a0757d Binary files /dev/null and b/manifest/gallary/AK-05.jpg differ diff --git a/manifest/jpeg/015a11a57f73ec3887bdf77f8f8a02f9.jpeg b/manifest/jpeg/015a11a57f73ec3887bdf77f8f8a02f9.jpeg new file mode 100644 index 0000000..5a2a8f6 Binary files /dev/null and b/manifest/jpeg/015a11a57f73ec3887bdf77f8f8a02f9.jpeg differ diff --git a/manifest/jpeg/070a095cf72042b8eebe78124f8225bb.jpeg b/manifest/jpeg/070a095cf72042b8eebe78124f8225bb.jpeg new file mode 100644 index 0000000..86578f3 Binary files /dev/null and b/manifest/jpeg/070a095cf72042b8eebe78124f8225bb.jpeg differ diff --git a/manifest/jpeg/fb7ab0a3878d821fffa8c1f06ec5e8d2.jpeg b/manifest/jpeg/fb7ab0a3878d821fffa8c1f06ec5e8d2.jpeg new file mode 100644 index 0000000..6305ffc Binary files /dev/null and b/manifest/jpeg/fb7ab0a3878d821fffa8c1f06ec5e8d2.jpeg differ diff --git a/manifest/jpeg/fbefd92059006090601cb6dafdce544c.jpeg b/manifest/jpeg/fbefd92059006090601cb6dafdce544c.jpeg new file mode 100644 index 0000000..fe7699a Binary files /dev/null and b/manifest/jpeg/fbefd92059006090601cb6dafdce544c.jpeg differ diff --git a/manifest/jpeg/fcff045964e4ac6fffd84a8192a0a393.jpeg b/manifest/jpeg/fcff045964e4ac6fffd84a8192a0a393.jpeg new file mode 100644 index 0000000..f599968 Binary files /dev/null and b/manifest/jpeg/fcff045964e4ac6fffd84a8192a0a393.jpeg differ diff --git a/manifest/main.py b/manifest/main.py new file mode 100644 index 0000000..5f11b30 --- /dev/null +++ b/manifest/main.py @@ -0,0 +1,63 @@ +#coding=utf-8 +''' +Created on Apr 23, 2018 +Desc: Webp convertor +@author: Mashiro https://2heng.xin +''' +import os +import sys +import json +import hashlib +from PIL import Image + +class Single(object): + def __init__(self, file, manifest): + self.file = file + self.mani = manifest + + def hash(self): + hasher = hashlib.md5() + with open('gallary/' + self.file, 'rb') as afile: + buf = afile.read() + hasher.update(buf) + self.hash = hasher.hexdigest() + self.jpeg = 'jpeg/' + self.hash + '.jpeg' + self.webp = 'webp/' + self.hash + '.webp' + + def optimize(self): + im = Image.open('gallary/' + self.file).convert('RGB') + im.save(self.jpeg, 'JPEG') # todo: TinyPNG API + im.save(self.webp, 'WEBP') + + def manifest(self): + self.mani[self.hash] = { + 'source': self.file, + 'jpeg': 'jpeg/' + self.hash + '.jpeg', + 'webp': 'webp/' + self.hash + '.webp' + } + + def main(self): + self.hash() + # if os.path.exists(self.jpeg) and os.path.exists(self.webp): + self.optimize() + self.manifest() + return self.mani + +def main(): + onlyfiles = [f for f in os.listdir('gallary') if os.path.isfile(os.path.join('gallary', f))] + id = 1 + Manifest = {} + + for f in onlyfiles: + worker = Single(f, Manifest) + Manifest = worker.main() + print(str(id) + '/' + str(len(onlyfiles))) + id += 1 + + with open('manifest.json', 'w+') as json_file: + json.dump(Manifest, json_file) + +if __name__ == '__main__': + main() + key = input('`manifest.json` saved. Press any key to quit.') + quit() \ No newline at end of file diff --git a/manifest/manifest.json b/manifest/manifest.json new file mode 100644 index 0000000..1b1d9cc --- /dev/null +++ b/manifest/manifest.json @@ -0,0 +1 @@ +{"070a095cf72042b8eebe78124f8225bb": {"source": "AK-01.jpg", "jpeg": "jpeg/070a095cf72042b8eebe78124f8225bb.jpeg", "webp": "webp/070a095cf72042b8eebe78124f8225bb.webp"}, "015a11a57f73ec3887bdf77f8f8a02f9": {"source": "AK-02.jpg", "jpeg": "jpeg/015a11a57f73ec3887bdf77f8f8a02f9.jpeg", "webp": "webp/015a11a57f73ec3887bdf77f8f8a02f9.webp"}, "fb7ab0a3878d821fffa8c1f06ec5e8d2": {"source": "AK-03.jpg", "jpeg": "jpeg/fb7ab0a3878d821fffa8c1f06ec5e8d2.jpeg", "webp": "webp/fb7ab0a3878d821fffa8c1f06ec5e8d2.webp"}, "fbefd92059006090601cb6dafdce544c": {"source": "AK-04.jpg", "jpeg": "jpeg/fbefd92059006090601cb6dafdce544c.jpeg", "webp": "webp/fbefd92059006090601cb6dafdce544c.webp"}, "fcff045964e4ac6fffd84a8192a0a393": {"source": "AK-05.jpg", "jpeg": "jpeg/fcff045964e4ac6fffd84a8192a0a393.jpeg", "webp": "webp/fcff045964e4ac6fffd84a8192a0a393.webp"}} \ No newline at end of file diff --git a/manifest/webp/015a11a57f73ec3887bdf77f8f8a02f9.webp b/manifest/webp/015a11a57f73ec3887bdf77f8f8a02f9.webp new file mode 100644 index 0000000..5510366 Binary files /dev/null and b/manifest/webp/015a11a57f73ec3887bdf77f8f8a02f9.webp differ diff --git a/manifest/webp/070a095cf72042b8eebe78124f8225bb.webp b/manifest/webp/070a095cf72042b8eebe78124f8225bb.webp new file mode 100644 index 0000000..e89c14a Binary files /dev/null and b/manifest/webp/070a095cf72042b8eebe78124f8225bb.webp differ diff --git a/manifest/webp/fb7ab0a3878d821fffa8c1f06ec5e8d2.webp b/manifest/webp/fb7ab0a3878d821fffa8c1f06ec5e8d2.webp new file mode 100644 index 0000000..9c8231c Binary files /dev/null and b/manifest/webp/fb7ab0a3878d821fffa8c1f06ec5e8d2.webp differ diff --git a/manifest/webp/fbefd92059006090601cb6dafdce544c.webp b/manifest/webp/fbefd92059006090601cb6dafdce544c.webp new file mode 100644 index 0000000..7a643f9 Binary files /dev/null and b/manifest/webp/fbefd92059006090601cb6dafdce544c.webp differ diff --git a/manifest/webp/fcff045964e4ac6fffd84a8192a0a393.webp b/manifest/webp/fcff045964e4ac6fffd84a8192a0a393.webp new file mode 100644 index 0000000..519dcc3 Binary files /dev/null and b/manifest/webp/fcff045964e4ac6fffd84a8192a0a393.webp differ