1

I'm creating the server for an ecommerce web app, and I cannot seem to resize the images into a perfect square. Is it that I need a set width and height to make it a perfect square?

Progman
  • 16,827
  • 6
  • 33
  • 48

1 Answers1

2

According to the sharp API documentation, the resize method can accept an optional "fit" parameter that would be useful.

See https://sharp.pixelplumbing.com/api-resize

That would give something like :

sharp(input)
.resize({width:512, height:512, fit:"cover"})
.toBuffer()
.then(data => {
    // ... do something with data
})