Upload to pip

This commit is contained in:
Andros 2017-10-29 20:42:13 +01:00
parent 356a7b9376
commit 3c975abc25
6 changed files with 98 additions and 46 deletions

10
.gitignore vendored Normal file
View File

@ -0,0 +1,10 @@
guetzli_recursively\.egg-info/
dist/
build/lib/
MANIFEST
setup\.cfg

7
LICENSE.txt Normal file
View 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.

View File

@ -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

View File

@ -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
View 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
View 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
'''
)