marlokessler / strapi-plugin-image-optimizer

Optimize your images for desktop, tablet and mobile and different image formats.
MIT License
14 stars 10 forks source link

Expected one of: av1, hevc for compression but received undefined of type undefined #40

Open mufteev opened 7 months ago

mufteev commented 7 months ago

Hi

In version 2.2.1 i get an error when loading an image:

[2024-04-11 23:30:20.440] error: Expected one of: av1, hevc for compression but received undefined of type undefined
Error: Expected one of: av1, hevc for compression but received undefined of type undefined
    at Object.invalidParameterError (/home/l/dev/landing/service/cms/node_modules/.pnpm/sharp@0.33.3/node_modules/sharp/lib/is.js:135:10)
    at Sharp.heif (/home/l/dev/landing/service/cms/node_modules/.pnpm/sharp@0.33.3/node_modules/sharp/lib/output.js:1069:16)
    at sharpAddFormatSettings (/home/l/dev/landing/service/cms/node_modules/.pnpm/strapi-plugin-image-optimizer@2.2.1_@strapi+core@0.0.0_@strapi+strapi@4.22.1_@strapi+utils@4.22.1_yup@1.4.0/node_modules/strapi-plugin-image-optimizer/dist/server/services/image-optimizer-service.js:82:10)
    at resizeFileTo (/home/l/dev/landing/service/cms/node_modules/.pnpm/strapi-plugin-image-optimizer@2.2.1_@strapi+core@0.0.0_@strapi+strapi@4.22.1_@strapi+utils@4.22.1_yup@1.4.0/node_modules/strapi-plugin-image-optimizer/dist/server/services/image-optimizer-service.js:52:21)
    at generateImage (/home/l/dev/landing/service/cms/node_modules/.pnpm/strapi-plugin-image-optimizer@2.2.1_@strapi+core@0.0.0_@strapi+strapi@4.22.1_@strapi+utils@4.22.1_yup@1.4.0/node_modules/strapi-plugin-image-optimizer/dist/server/services/image-optimizer-service.js:44:21)
    at /home/l/dev/landing/service/cms/node_modules/.pnpm/strapi-plugin-image-optimizer@2.2.1_@strapi+core@0.0.0_@strapi+strapi@4.22.1_@strapi+utils@4.22.1_yup@1.4.0/node_modules/strapi-plugin-image-optimizer/dist/server/services/image-optimizer-service.js:28:38
    at Array.forEach (<anonymous>)
    at /home/l/dev/landing/service/cms/node_modules/.pnpm/strapi-plugin-image-optimizer@2.2.1_@strapi+core@0.0.0_@strapi+strapi@4.22.1_@strapi+utils@4.22.1_yup@1.4.0/node_modules/strapi-plugin-image-optimizer/dist/server/services/image-optimizer-service.js:27:15
    at Array.forEach (<anonymous>)
    at optimizeImage (/home/l/dev/landing/service/cms/node_modules/.pnpm/strapi-plugin-image-optimizer@2.2.1_@strapi+core@0.0.0_@strapi+strapi@4.22.1_@strapi+utils@4.22.1_yup@1.4.0/node_modules/strapi-plugin-image-optimizer/dist/server/services/image-optimizer-service.js:26:13)

I think this is due to the fact that when sharpInstance is initialized, the compression parameter is not passed for heif option: https://github.com/marlokessler/strapi-plugin-image-optimizer/blob/26a3212c70d4714859261574cb4c696b8cedcee0/server/services/image-optimizer-service.ts#L128-L138

Sharp documentation: https://sharp.pixelplumbing.com/api-output#heif

I use the following plugin configuration:

'image-optimizer': {
  enabled: true,
  config: {
    include: ["jpeg", "jpg", "png"],
    exclude: ["gif"],
    formats: ["original", "webp"],
    sizes: [
      {
        name: "xs",
        width: 300,
      },
      {
        name: "sm",
        width: 768,
      },
      {
        name: "md",
        width: 1280,
      },
      {
        name: "lg",
        width: 1920,
      },
      {
        name: "xl",
        width: 2840,
        withoutEnlargement: true,
      },
      {
        name: "original",
      },
    ],
    additionalResolutions: [1.5, 3],
    quality: 70,
  } satisfies ImageOptimizerConfig
}
wendelsantosd commented 7 months ago

Same issue here.

impcyber commented 7 months ago

After this commit https://github.com/lovell/sharp/commit/3043e01171756345d5098485d4d95cbe0ca9d8ec compress option in heic becomes mandatory. https://github.com/lovell/sharp/issues/3740 So try to downgrade to sharp to 0.32.6 version