Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.resize does not throw error when options.width or options.height is supplied with float number. #1817

Closed
yqlim opened this issue Jul 30, 2019 · 3 comments

Comments

@yqlim
Copy link

yqlim commented Jul 30, 2019

I'm using version 0.23.0.

When used with width and height as params and supplied with a float number, an error will be thrown:

let width = 30/100;
let height = width;

sharp(buffer)
  .resize(width, height, {
    /* options */
  })

// Throws `Error: Expected positive integer for width but received 0.3 of type number`

However, when the same is written like so, no error will be thrown. It seems that the whole .resize operation is simply skipped:

let width = 30/100;
let height = width;

sharp(buffer)
  .resize({
    width,
    height,
    /* options */
  })

I wasted half my day trying to find what went wrong because my image can never be resized.

According to the documentation, the options.width and options.height take higher priority. So it seems the same error should also be thrown here.

@lovell
Copy link
Owner

lovell commented Jul 30, 2019

Hi, happy to accept a PR to address this if you're able.

@lovell
Copy link
Owner

lovell commented Aug 16, 2019

Commit 69fe21a adds unit tests and the logic that would have caught this. Thanks for reporting, this will be in v0.23.1.

@lovell lovell added this to the 0.23.1 milestone Aug 16, 2019
@lovell
Copy link
Owner

lovell commented Sep 26, 2019

v0.23.1 now available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants