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

Migrating from v0.16.2 to v0.27.1 #2560

Closed
jatinvmehta opened this issue Feb 4, 2021 · 6 comments
Closed

Migrating from v0.16.2 to v0.27.1 #2560

jatinvmehta opened this issue Feb 4, 2021 · 6 comments
Labels

Comments

@jatinvmehta
Copy link

jatinvmehta commented Feb 4, 2021

In older version of Sharp v0.16.2, it had function called min(). This was deprecated based on documentation and replace with {fit: sharp.fit.outside} options.

Problem : When we upload same original image with newer function, we are not getting same quality and there is visible difference in image along with size.

Old Code
function resizeImage(image) {
return new Promise((resolve, reject) => {

let _sharp = sharp(image.buffer).resize(image.width, image.height);

if (!image.bookCover) {
  _sharp.min()
}

_sharp.toBuffer((err, buffer) => {

  if (err) {
    return reject(err.message);
  }

  resolve(buffer);

});

});
}

Image resized with Old Code --> https://orion-uploads.openroadmedia.com/md_7d97a8278834-medieval-weapons.jpg

New Code
export const resizeImage = async (file) => {
return await sharp(file.buffer).resize(file.width, file.height, {fit: sharp.fit.outside}).toBuffer();
};

Image resized with New Code --> https://orion-uploads.openroadmedia.com/md_5e4601a8fc7f-medieval-weapons.jpg

We used same original image to test. We scan through entire documentation and tried various other options like karnel, sharpen etc but we aren't able to generate same image.

I will really appreciate any help on this. Thanks in advance

@lovell
Copy link
Owner

lovell commented Feb 4, 2021

Are you able to share the input image?

@jatinvmehta
Copy link
Author

jatinvmehta commented Feb 4, 2021

@lovell - Sure. Here is link to original image
https://orion-uploads.s3.amazonaws.com/medieval-weapons.jpg

@lovell
Copy link
Owner

lovell commented Feb 4, 2021

Running:

sharp("medieval-weapons.jpg")
  .resize(682, 287, { fit: sharp.fit.outside })
  .toFile("out.jpg")

...results in:

...which looks OK to me.

If you're still having problems, please can you provide the complete, standalone code used to produce these images, perhaps as a separate repo.

@jatinvmehta
Copy link
Author

@lovell - Thank you very much for prompt reply. I will try to provide separate repo. Only notable difference between your code and ours is, we are returning buffer where as you are saving it as file. We will try that option first and if still see the issue, will create repo. Again, thank you very much

@lovell
Copy link
Owner

lovell commented Mar 2, 2021

Were you able to make any progress with this?

@lovell
Copy link
Owner

lovell commented Mar 8, 2021

Closing due to inactivity but please feel free to reopen with more details if further help is required.

@lovell lovell closed this as completed Mar 8, 2021
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