【问题标题】:Issue: Image Resize with Sharp throwing exception [closed]问题:使用 Sharp 抛出异常调整图像大小 [关闭]
【发布时间】:2019-08-18 23:22:29
【问题描述】:

之前我使用的是 0.22.0 版本,但我的构建未能部署,所以我尝试使用 0.21.0,然后它抛出运行时异常“预期宽度为正整数,但在

【问题讨论】:

  • 如果可能的话,代码 sn-p 在这里会很有用。
  • sharp(inputPhotoUrl).resize({ height: 230, width: 534 }).toFile(propotionOutPhoto) .then(function (newFileInfo) { console.log("Success"); }) 。 catch(function (err) { console.log("错误发生", err); });

标签: node.js sharp


【解决方案1】:

根据您的评论,这是您的代码:

sharp(inputPhotoUrl)
  .resize({ height: 230, width: 534 })
  .toFile(propotionOutPhoto)
  .then(function(newFileInfo) {
    console.log("Success");
  })
  .catch(function(err) {
    console.log("Error occured ", err);
  });

您对resize 的论点看起来是有效的,但我从不这样给出widthheight,因为这只是另一种方式(尽管,这应该根据文档工作)。

我建议您将宽度和高度作为第一个和第二个参数传递,然后如果您有任何其他选项将它们作为对象传递。这对我总是有用(宽度,高度,{options}):

sharp(inputPhotoUrl)
  .resize(534, 230)
  .toFile(propotionOutPhoto)
  .then(() => console.log("Success"))
  .catch((error) => console.log("Error occured", error));

【讨论】:

    猜你喜欢
    • 2021-04-25
    • 2019-11-15
    • 2011-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-31
    • 2022-09-23
    • 1970-01-01
    相关资源
    最近更新 更多