Search code examples
apostrophe-cms

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


I found this page in the documentation (https://docs.apostrophecms.org/apostrophe/modules/apostrophe-attachments#options), but it doesn't really explain how and where you actually use addImageSizes.

I tried creating an apostrophe-attachments folder in my modules, adding an index.js file and doing this...

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

But that gives me an error, cannot read property of middleware.

Any ideas?


Solution

  • Do not use extend when you are just improving a core module with some new configuration or project-level methods.

    Using extend like this will break the link between your configuration of it and the original module, creating an entirely new module that has no idea how to serve attachments.

    So, just write:

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

    Leaving out extend.