mirror of
https://github.com/tanrax/guetzli-recursively.git
synced 2024-11-23 02:35:40 +01:00
Upload to pip
This commit is contained in:
parent
356a7b9376
commit
3c975abc25
10
.gitignore
vendored
Normal file
10
.gitignore
vendored
Normal file
@ -0,0 +1,10 @@
|
||||
|
||||
guetzli_recursively\.egg-info/
|
||||
|
||||
dist/
|
||||
|
||||
build/lib/
|
||||
|
||||
MANIFEST
|
||||
|
||||
setup\.cfg
|
7
LICENSE.txt
Normal file
7
LICENSE.txt
Normal file
@ -0,0 +1,7 @@
|
||||
Copyright 2017
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
10
README.md
10
README.md
@ -10,16 +10,22 @@ Guetzli must be installed on your system. Follow the official instructions.
|
||||
|
||||
and 2.7.10 or Python 3.
|
||||
|
||||
After
|
||||
|
||||
```bash
|
||||
pip3 install guetzli-recursively
|
||||
```
|
||||
|
||||
# Use
|
||||
|
||||
```bash
|
||||
python3 guetzli-recursively.py [folder]
|
||||
guetzli_recursively [folder]
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
```bash
|
||||
python3 guetzli-recursively.py img
|
||||
guetzli_recursively img/
|
||||
```
|
||||
|
||||
out
|
||||
|
@ -1,44 +0,0 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
from os import path, walk, remove, rename
|
||||
from imghdr import what
|
||||
from subprocess import call
|
||||
from sys import argv
|
||||
top_dir = argv[1]
|
||||
TEMP_FILE = 'temp.jpg'
|
||||
TYPES = ('jpeg',)
|
||||
|
||||
for dirpath, dirnames, files in walk(top_dir):
|
||||
for name in files:
|
||||
url = path.join(dirpath, name)
|
||||
# Check type
|
||||
if what(url) in TYPES:
|
||||
# Get urls
|
||||
print(url)
|
||||
url_out = path.join(top_dir, TEMP_FILE)
|
||||
# Remove temp image
|
||||
try:
|
||||
remove(url_out)
|
||||
except:
|
||||
pass
|
||||
# Execute guetzli
|
||||
call(['guetzli', url, url_out])
|
||||
# Print your have saved
|
||||
size_source = path.getsize(url)
|
||||
try:
|
||||
size_out = path.getsize(url_out)
|
||||
except:
|
||||
size_out = size_source
|
||||
size_acurate = 100 * size_out / size_source
|
||||
# Check if it is cost effective to replace it
|
||||
if size_acurate < 100:
|
||||
# Remove source
|
||||
try:
|
||||
remove(url)
|
||||
except:
|
||||
pass
|
||||
# Move temp to source
|
||||
rename(url_out, url)
|
||||
print('Save ' + str(round(100 - size_acurate, 2)) + '%')
|
||||
else:
|
||||
print('It is not necessary to optimize')
|
54
guetzli_recursively.py
Normal file
54
guetzli_recursively.py
Normal file
@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
# Libraries
|
||||
import click
|
||||
from os import path, walk, remove, rename
|
||||
from imghdr import what
|
||||
from subprocess import call
|
||||
|
||||
# Variables
|
||||
TEMP_FILE = 'temp.jpg'
|
||||
TYPES = ('jpeg',)
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument('folder', type=click.Path(exists=True))
|
||||
def run(folder):
|
||||
for dirpath, dirnames, files in walk(folder):
|
||||
for name in files:
|
||||
url = path.join(dirpath, name)
|
||||
# Check type
|
||||
if what(url) in TYPES:
|
||||
# Get urls
|
||||
click.echo(url)
|
||||
url_out = path.join(folder, TEMP_FILE)
|
||||
# Remove temp image
|
||||
try:
|
||||
remove(url_out)
|
||||
except:
|
||||
pass
|
||||
# Execute guetzli
|
||||
call(['guetzli', url, url_out])
|
||||
# Print your have saved
|
||||
size_source = path.getsize(url)
|
||||
try:
|
||||
size_out = path.getsize(url_out)
|
||||
except:
|
||||
size_out = size_source
|
||||
size_acurate = 100 * size_out / size_source
|
||||
# Check if it is cost effective to replace it
|
||||
if size_acurate < 100:
|
||||
# Remove source
|
||||
try:
|
||||
remove(url)
|
||||
except:
|
||||
pass
|
||||
# Move temp to source
|
||||
rename(url_out, url)
|
||||
click.echo('Save ' + str(round(100 - size_acurate, 2)) + '%')
|
||||
else:
|
||||
click.echo('It is not necessary to optimize')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
19
setup.py
Normal file
19
setup.py
Normal file
@ -0,0 +1,19 @@
|
||||
from setuptools import setup
|
||||
setup(
|
||||
name = 'guetzli_recursively',
|
||||
py_modules=['guetzli_recursively'],
|
||||
version = '1.1.0',
|
||||
description = 'Script in Python to convert all the jpeg of a folder recursively with Guetzli.',
|
||||
author = 'Andros Fenollosa',
|
||||
author_email = 'andros@fenollosa.email',
|
||||
url = 'https://github.com/tanrax/guetzli-recursively',
|
||||
keywords = ['guetzli', 'jpeg', 'recursive'],
|
||||
classifiers = [],
|
||||
install_requires=[
|
||||
'Click>=6.7',
|
||||
],
|
||||
entry_points='''
|
||||
[console_scripts]
|
||||
guetzli_recursively=guetzli_recursively:run
|
||||
'''
|
||||
)
|
Loading…
Reference in New Issue
Block a user