Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_options(self, option_name, input_, output):
opt = options.normalize_options({
option_name: input_
})
assert opt[option_name] == output
def test_invalid_resize_option(self):
with pytest.raises(ValueError):
options.normalize_options({"resize": "foobar"})
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