Skip to content

Commit

Permalink
fix: handling of 0 parameters for avif
Browse files Browse the repository at this point in the history
  • Loading branch information
boidolr committed Oct 14, 2023
1 parent a6a3102 commit e3711fd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions pre_commit_images/optimize_avif.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ def main(argv: Optional[Sequence[str]] = None) -> int:
)
args = parser.parse_args(argv)

if not args.qmin and not args.qmax and not args.quality:
if args.qmin is None and args.qmax is None and args.quality is None:
args.quality = 75

if args.qmin and args.quality or args.qmax and args.quality:
if args.quality is not None and (args.qmin is not None or args.qmax is not None):
sys.exit("Can not use both `qmin`/`qmax` and `quality`")

if args.qmin or args.qmax:
if args.qmin is not None or args.qmax is not None:
warnings.warn(
"`qmin`/`qmax` are deprecated, use `quality` instead"
" - it will be the only option for future AVIF versions",
category=DeprecationWarning,
)

options = {option: value for option, value in vars(args).items() if value}
options = {option: value for option, value in vars(args).items() if value is not None}

def optimize(source: Path, target: IO[bytes]) -> None:
im = Image.open(source)
Expand Down
2 changes: 1 addition & 1 deletion tests/optimize_avif_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def image(tmpdir, original_image):

def test_qmin_qmax_deprecated(image):
with pytest.deprecated_call():
assert main(("-min", "10", str(image))) == 0
assert main(("-min", "0", str(image))) == 0


def test_qmin_qmax_and_quality(image):
Expand Down

0 comments on commit e3711fd

Please sign in to comment.