From 13c4d2ff3faef177c57e57aa52ffbc4ddd29208a Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Fri, 5 Jan 2018 16:28:24 +0100 Subject: [PATCH] Add quality --- README.md | 8 ++++++++ guetzli_recursively.py | 17 +++++++++++++---- setup.py | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ea386ee..b94d396 100644 --- a/README.md +++ b/README.md @@ -38,3 +38,11 @@ It is not necessary to optimize img/portfolio/home.jpg Save 3% ``` + +# Quality + +Must be greater than or equal to 84. + +```bash +guetzli_recursively --quality 85 img/ +``` diff --git a/guetzli_recursively.py b/guetzli_recursively.py index 63ba1d4..16d17d7 100644 --- a/guetzli_recursively.py +++ b/guetzli_recursively.py @@ -9,16 +9,24 @@ from subprocess import call # Variables TEMP_FILE = 'temp.jpg' TYPES = ('jpeg',) +LIMIT_QUALITY = 84 @click.command() +@click.option( + '--quality', + default=100, + help='Quality >= ${quality} [default 100].'.format( + quality=LIMIT_QUALITY + ) +) @click.argument('folder', type=click.Path(exists=True)) -def run(folder): +def run(quality, folder): for dirpath, dirnames, files in walk(folder): for name in files: url = path.join(dirpath, name) # Check type - if what(url) in TYPES: + if what(url) in TYPES or quality >= LIMIT_QUALITY: # Get urls click.echo(url) url_out = path.join(folder, TEMP_FILE) @@ -28,7 +36,7 @@ def run(folder): except: pass # Execute guetzli - call(['guetzli', url, url_out]) + call(['guetzli', '--quality', str(quality), url, url_out]) # Print your have saved size_source = path.getsize(url) try: @@ -45,7 +53,8 @@ def run(folder): pass # Move temp to source rename(url_out, url) - click.echo('Save ' + str(round(100 - size_acurate, 2)) + '%') + click.echo( + 'Save ' + str(round(100 - size_acurate, 2)) + '%') else: click.echo('It is not necessary to optimize') diff --git a/setup.py b/setup.py index 6849af6..f0f2540 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name = 'guetzli_recursively', py_modules=['guetzli_recursively'], - version = '1.1.0', + version = '1.2.0', description = 'Script in Python to convert all the jpeg of a folder recursively with Guetzli.', author = 'Andros Fenollosa', author_email = 'andros@fenollosa.email',