我正在尝试使用 Nodejs Sharp 包调整图像大小/转换为 png,而不进行裁剪。根据文档,它是 .max() 方法,遗憾的是,在调整大小为 png 时,该方法不起作用(图像被裁剪)。有什么解决方法吗?
最佳答案
如果您使用sharp ,那么您可以使用达到您想要的结果
sharp()
.resize(400, 400, {
fit: sharp.fit.inside,
withoutEnlargement: true, // if image's original width or height is less than specified width and height, sharp will do nothing(i.e no enlargement)
})
inside
:将图像放入宽度 400 和高度 400 内,而不裁剪图像的任何部分,也不添加黑色填充 用于调整输出图像的尺寸- 从技术上讲,它会将图像大小调整为尽可能大,同时确保其尺寸小于或等于指定的尺寸。
关于node.js - 使用node.js和Sharp包将非裁剪调整为png,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47802542/