Astro CouldNotTransformImage input image exceeds pixel limit

  1. #Astro

如果你在開發上遇到 astro build 的的時候,出現下面的錯誤,就代表圖片的大小超過 sharp 預設的上限了

[CouldNotTransformImage] Could not transform image `/_astro/1F0JytL1HhpVGqH9SFd4I6g.-wAHN69G.gif`. See the stack trace for more information.
  Hint:
    This is often caused by a corrupted or malformed image. Re-exporting the image from your image editor may fix this issue.
  Error reference:
    https://docs.astro.build/en/reference/errors/could-not-transform-image/
  Stack trace:
    at generateImageInternal (file:///Users/shiny/code/astro-blog/node_modules/astro/dist/assets/build/generate.js:129:21)
    at async file:///Users/shiny/code/astro-blog/node_modules/p-queue/dist/index.js:187:36
  Caused by:
  Input image exceeds pixel limit

error Command failed with exit code 1.

這個時候只要更新 astro.config.mjssharpImageService 的上限設定為無限即可

import { defineConfig, sharpImageService } from "astro/config";

export default defineConfig({
  image: {
    service: sharpImageService({ limitInputPixels: false }),
  },
});

References

  1. https://github.com/withastro/astro/issues/8886#discussion_r1440146471