From 9a4e72d42a355ae85d18ec63ce1e81cae768cbcb Mon Sep 17 00:00:00 2001 From: Sam Holt Date: Tue, 14 Jul 2020 22:39:09 +0100 Subject: [PATCH] feat: Add memlimit arg --- guetzli_recursively.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/guetzli_recursively.py b/guetzli_recursively.py index 7584b9c..9e2c674 100644 --- a/guetzli_recursively.py +++ b/guetzli_recursively.py @@ -14,14 +14,19 @@ LIMIT_QUALITY = 84 @click.command() @click.option( - '--quality', - default=100, - help='Quality >= {quality} [default 100].'.format( - quality=LIMIT_QUALITY - ) + '--quality', + default=100, + help='Quality >= {quality} [default 100].'.format( + quality=LIMIT_QUALITY + ) +) +@click.option( + '--memlimit', + default=28000, + help='Memory limit in MB. Guetzli will fail if unable to stay under the limit. Default is 28000 MB' ) @click.argument('folder', type=click.Path(exists=True)) -def run(quality, folder): +def run(quality, memlimit, folder): for dirpath, dirnames, files in walk(folder): for name in files: url = path.join(dirpath, name) @@ -36,7 +41,10 @@ def run(quality, folder): except: pass # Execute guetzli - call(['guetzli', '--quality', str(quality), url, url_out]) + args = ['guetzli', '--quality', + str(quality), '--memlimit', str(memlimit), url, url_out] + print(' '.join(args)) + call(args) # Print your have saved size_source = path.getsize(url) try: @@ -54,7 +62,7 @@ def run(quality, folder): # Move temp to source rename(url_out, url) click.echo( - 'Save ' + str(round(100 - size_acurate, 2)) + '%') + 'Save ' + str(round(100 - size_acurate, 2)) + '%') else: click.echo('It is not necessary to optimize')