Adds webp support in the CLI

This commit is contained in:
Fabien LOISON 2021-04-15 18:15:11 +02:00
parent 31d1e5082f
commit 68ca4d3e78
No known key found for this signature in database
GPG Key ID: FF90CA148348048E
2 changed files with 30 additions and 3 deletions

View File

@ -16,11 +16,12 @@ YOGA Image Command Line Interface
-h, --help show this help message and exit
-v, --verbose enable verbose mode
-q, --quiet enable quiet mode (takes precedence over verbose)
--output-format {orig,auto,jpeg,png}
--output-format {orig,auto,jpeg,png,webp,webpl}
format of the output image
--resize {orig,<SIZE>,<WIDTH>x<HEIGHT>}
resize the image
--jpeg-quality 0-100 JPEG quality if the output format is set to 'jpeg'
--webp-quality 0-100 WEBP quality if the output format is set to 'webp'
--opacity-threshold 0-255
threshold below which a pixel is considered transparent
@ -94,6 +95,25 @@ The default JPEG quality is ``84%``.
This option has effect only when the output image is a JPEG.
Output WEBP Quality
-------------------
YOGA allows you to tune the desired quality of the WEBP it outputs with the ``--webp-quality`` option. This option takes an integer between ``0`` and ``100`` as parameter:
* ``0``: ugly images but smaller files,
* ``100``: best quality images but larger files.
The default WEBP quality is ``90%``.
::
yoga image --output-format=webp --webp-quality=90 input.png output.webp
.. NOTE::
This option has effect only when the output image is a lossy WEBP.
Opacity Threshold
-----------------

View File

@ -40,8 +40,8 @@ def add_image_cli_options(parser, prefix=""):
parser.add_argument(
"--%soutput-format" % prefix,
help="format of the output image",
metavar="{orig,auto,jpeg,png}",
choices=["orig", "auto", "jpeg", "jpg", "png"],
metavar="{orig,auto,jpeg,png,webp,webpl}",
choices=["orig", "auto", "jpeg", "jpg", "png", "webp", "webpl"],
default=DEFAULT_OPTIONS["output_format"],
)
parser.add_argument(
@ -58,6 +58,13 @@ def add_image_cli_options(parser, prefix=""):
type=partial(_type_range, 0, 100),
default=DEFAULT_OPTIONS["jpeg_quality"],
)
parser.add_argument(
"--%swebp-quality" % prefix,
help="WEBP quality if the output format is set to 'webp'",
metavar="0-100",
type=partial(_type_range, 0, 100),
default=DEFAULT_OPTIONS["webp_quality"],
)
parser.add_argument(
"--%sopacity-threshold" % prefix,
help="threshold below which a pixel is considered transparent",