如何在 Apostrophe CMS 中添加自定义图像大小?

How do you add a custom image size in Apostrophe CMS?

我在文档 (https://docs.apostrophecms.org/apostrophe/modules/apostrophe-attachments#options) 中找到了这个页面,但它并没有真正解释您实际使用的方式和位置 addImageSizes

我尝试在我的模块中创建一个 apostrophe-attachments 文件夹,添加一个 index.js 文件并执行此操作...

module.exports = {
  extend: "apostrophe-module",
  imageSizes: [
    {
      name: 'tiny',
      width: 100,
      height: 100
   }
  ]
}

但这给了我一个错误,无法读取 属性 的中间件。

有什么想法吗?

当你只是用一些新的配置或项目级方法改进核心模块时,不要使用 extend

像这样使用 extend 将打破您的配置与原始模块之间的 link,创建一个不知道如何提供附件的全新模块。

所以,只写:

module.exports = {
  addImageSizes: [
    {
      name: 'tiny',
      width: 100,
      height: 100
   }
  ]
}

遗漏extend.

添加到 Tom 的回答中,您还可以通过将其放入 app.js 来为系统中使用 apostrophe-attachments 小部件的所有模块全局设置新图像大小。只需将其添加到您的小部件声明下即可。

'apostrophe-attachments': {
      addImageSizes: [{
        name: 'tiny',
        width: 100,
        height: 100
      }]
    },

关于imageSizesaddImageSizes的用法:在apostrophe-attachments模块的注释中,它指出:

Like addImageSizes, but Apostrophe's standard sizes are completely replaced. Bear in mind // that certain sizes are used by Apostrophe's editing interface unless overridden. We recommend // using addImageSizes.

因此您可以使用 imageSizes,替换开箱即用的图像尺寸,请牢记这一点。