vseventer/sharp-cli

Unexpected error for any CPU effort outside of the 0...6 range

Opened this issue · 1 comments

CPU effort is one of the output options (--effort) for the PNG, WebP, GIF, AVIF, HEIF and JPEG XL image file formats. According to Sharp's API documentation, the following values are allowed:

  • PNG: number between 1 (fastest) and 10 (slowest)
  • WebP: number between 0 (fastest) and 6 (slowest)
  • GIF: number between 1 (fastest) and 10 (slowest)
  • AVIF: number between 0 (fastest) and 9 (slowest)
  • HEIF: number between 0 (fastest) and 9 (slowest)
  • JPEG XL: number between 3 (fastest) and 9 (slowest)

But the CLI for Sharp throws an unexpected error for any CPU effort outside of the 0...6 range.

Example:

sharp -i "image.jpg" -o "image.avif" --effort 9 -f "avif"

Expected result:

The input file is converted from JPEG to AVIF with a CPU effort of 9.

Actual result:

An InvalidParameterError is thrown. Error message: "Expected integer between 0 and 6 for effort but received 9 of type number"

Yes, this seems to be a bug in the CLI - thanks for reporting.