Skip to content

Image not being resized #1427

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

Closed
hornta opened this issue Oct 23, 2018 · 3 comments
Closed

Image not being resized #1427

hornta opened this issue Oct 23, 2018 · 3 comments
Labels

Comments

@hornta
Copy link

hornta commented Oct 23, 2018

When performing a resize, then an extract and then an resize again, the final image is not being resized(the actual image is resized, but not the dimensions)

Clone my repo and test https://github.com/hornta/sharp-resize-bug

const sharp = require('sharp');
sharp('dog.jpg')
  .resize(50)
  .extract({
    left: 0, 
    top: 0, 
    width: 25, 
    height: 25
  })
  .resize(1000)
  .jpeg()
  .toFile('bigDog.jpg');

bigDog.jpg results in a 25x25 pixels image when it should end up with a 1000px wide image

@lovell
Copy link
Owner

lovell commented Oct 23, 2018

Hello, if you want to resize to 50 pixels wide, extract the top-left 25x25 region then resize to 1000 pixels wide, try something like the following:

sharp('dog.jpg')
  .resize(50)
  .extract({
    left: 0, 
    top: 0, 
    width: 25, 
    height: 25
  })
  .toBuffer()
  .then(data => sharp(data)
    .resize(1000)
    .toFile('bigDog.jpg')
  );

@hornta
Copy link
Author

hornta commented Oct 23, 2018

Is there a reason I have to do it like that? Why is not my example working? I think most people would expect it to work like my example. This was just a very specific example, but I need to follow that order.

@lovell
Copy link
Owner

lovell commented Oct 23, 2018

Although resize can be called multiple times to set/update options, the current implementation supports one resize operation per instance.

You may be interested in a discussion about an alternative API at #241.

@lovell lovell closed this as completed Nov 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants