我正在为电子商务web应用程序创建服务器,并且我似乎无法将图像调整为完美的正方形。我需要一个固定的宽度和高度来使它成为一个完全正方形吗?
根据sharp API文档,resize方法可以接受一个可选的"fit"参数
见https://sharp.pixelplumbing.com/api-resize
将会得到如下内容:
sharp(input)
.resize({width:512, height:512, fit:"cover"})
.toBuffer()
.then(data => {
// ... do something with data
})