mirror of
https://github.com/tanrax/guetzli-recursively.git
synced 2024-11-09 22:45:41 +01:00
Add quality
This commit is contained in:
parent
3c975abc25
commit
13c4d2ff3f
@ -38,3 +38,11 @@ It is not necessary to optimize
|
|||||||
img/portfolio/home.jpg
|
img/portfolio/home.jpg
|
||||||
Save 3%
|
Save 3%
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Quality
|
||||||
|
|
||||||
|
Must be greater than or equal to 84.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
guetzli_recursively --quality 85 img/
|
||||||
|
```
|
||||||
|
@ -9,16 +9,24 @@ from subprocess import call
|
|||||||
# Variables
|
# Variables
|
||||||
TEMP_FILE = 'temp.jpg'
|
TEMP_FILE = 'temp.jpg'
|
||||||
TYPES = ('jpeg',)
|
TYPES = ('jpeg',)
|
||||||
|
LIMIT_QUALITY = 84
|
||||||
|
|
||||||
|
|
||||||
@click.command()
|
@click.command()
|
||||||
|
@click.option(
|
||||||
|
'--quality',
|
||||||
|
default=100,
|
||||||
|
help='Quality >= ${quality} [default 100].'.format(
|
||||||
|
quality=LIMIT_QUALITY
|
||||||
|
)
|
||||||
|
)
|
||||||
@click.argument('folder', type=click.Path(exists=True))
|
@click.argument('folder', type=click.Path(exists=True))
|
||||||
def run(folder):
|
def run(quality, folder):
|
||||||
for dirpath, dirnames, files in walk(folder):
|
for dirpath, dirnames, files in walk(folder):
|
||||||
for name in files:
|
for name in files:
|
||||||
url = path.join(dirpath, name)
|
url = path.join(dirpath, name)
|
||||||
# Check type
|
# Check type
|
||||||
if what(url) in TYPES:
|
if what(url) in TYPES or quality >= LIMIT_QUALITY:
|
||||||
# Get urls
|
# Get urls
|
||||||
click.echo(url)
|
click.echo(url)
|
||||||
url_out = path.join(folder, TEMP_FILE)
|
url_out = path.join(folder, TEMP_FILE)
|
||||||
@ -28,7 +36,7 @@ def run(folder):
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
# Execute guetzli
|
# Execute guetzli
|
||||||
call(['guetzli', url, url_out])
|
call(['guetzli', '--quality', str(quality), url, url_out])
|
||||||
# Print your have saved
|
# Print your have saved
|
||||||
size_source = path.getsize(url)
|
size_source = path.getsize(url)
|
||||||
try:
|
try:
|
||||||
@ -45,7 +53,8 @@ def run(folder):
|
|||||||
pass
|
pass
|
||||||
# Move temp to source
|
# Move temp to source
|
||||||
rename(url_out, url)
|
rename(url_out, url)
|
||||||
click.echo('Save ' + str(round(100 - size_acurate, 2)) + '%')
|
click.echo(
|
||||||
|
'Save ' + str(round(100 - size_acurate, 2)) + '%')
|
||||||
else:
|
else:
|
||||||
click.echo('It is not necessary to optimize')
|
click.echo('It is not necessary to optimize')
|
||||||
|
|
||||||
|
2
setup.py
2
setup.py
@ -2,7 +2,7 @@ from setuptools import setup
|
|||||||
setup(
|
setup(
|
||||||
name = 'guetzli_recursively',
|
name = 'guetzli_recursively',
|
||||||
py_modules=['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.',
|
description = 'Script in Python to convert all the jpeg of a folder recursively with Guetzli.',
|
||||||
author = 'Andros Fenollosa',
|
author = 'Andros Fenollosa',
|
||||||
author_email = 'andros@fenollosa.email',
|
author_email = 'andros@fenollosa.email',
|
||||||
|
Loading…
Reference in New Issue
Block a user