How to use the yoga.image.options.normalize_options function in yoga

To help you get started, we’ve selected a few yoga examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wanadev / yoga / test / test_image_options.py View on Github external
def test_options(self, option_name, input_, output):
        opt = options.normalize_options({
            option_name: input_
            })
        assert opt[option_name] == output
github wanadev / yoga / test / test_image_options.py View on Github external
def test_invalid_resize_option(self):
        with pytest.raises(ValueError):
            options.normalize_options({"resize": "foobar"})
github wanadev / yoga / yoga / image / __init__.py View on Github external
def optimize(input_file, output_file, options={}, verbose=False, quiet=False):
    options = normalize_options(options)

    image = Image.open(input_file)

    if options["output_format"] == "orig" and image.format not in ("JPEG", "PNG"):                      # noqa
        raise ValueError("The input image must be a JPEG or a PNG when setting 'output_format' to 'orig'")    # noqa

    if not hasattr(output_file, "write"):
        output_file = open(output_file, "ab")

    # resize
    if options["resize"] != "orig":
        image.thumbnail(options["resize"], Image.LANCZOS)

    # output format
    output_format = None