我正在尝试使用Nodejs sharp包调整图像大小/转换为png,而不进行裁剪。根据文档,它是.max()方法,遗憾的是,当调整大小为png时,该方法不起作用(图像被裁剪)。有什么解决方法吗?
发布于 2020-02-05 03:30:54
嘿,如果你还在疑惑,这就是你怎么做的。
await sharp(postImage).resize(800, 900, {fit:"contain"}).toFile("/output/path");在.resize()的第三个参数中,你可以提到fit,它可以是'fill','contain‘等. 'contain’将嵌入图像而不改变其原始的高度和宽度,并用背景颜色填充(def.黑色)。“‘fill”将拉伸图像。For More
发布于 2021-07-21 20:41:02
如果您使用的是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 ,并且不向输出imagehttps://stackoverflow.com/questions/47802542
复制相似问题