处理图像时,从“ cmyk”到“ srgb”的路径未知

Dar*_*ren 5 javascript reactjs graphql gatsby

CodeSandbox- https: //codesandbox.io/s/jj597mrvmw

我从外部API返回到我的GatsbyJS / ReactJS网站的某些数据有问题。

更具体地说,问题似乎是在GraphQL查询上使用gatsby-imagegatsby-plugin-sharp使用API 处理图像时出现的。...GatsbyImageSharpFluid

从1000幅图像来看,似乎只有1幅是麻烦的,返回了错误

Errors:
  icc_transform: no input profile
  vips_colourspace: no known route from 'cmyk' to 'srgb'
Run Code Online (Sandbox Code Playgroud)

我可以过滤掉该图像,但担心将来的图像作为API更新可能会导致相同的问题。

我怎么能够

  1. 解决此错误提示,sharp以便可以处理图像吗?要么,
  2. filter在处理时返回此错误的图像createRemoteFileNode,或
  3. catch (error)或中跳过有问题的图像
  4. 任何其他想法/解决方案

createRemoteFileNodegatsby-node.js

exports.sourceNodes = async ({ actions, store, cache, createNodeId }) => {
  const { createNode, createNodeField } = actions;
  const { data } = await axios.get(API_URI);

  for (const event of data._embedded.events) {
    let fileNode;
    let output = [];
    let filterResults = event.images.filter(e => e.width >= 1900);
    output.push(...filterResults);
    try {
      fileNode = await createRemoteFileNode({
        url: output[0].url,
        cache,
        store,
        createNode,
        createNodeId,
      });
      await createNodeField({
        node: fileNode,
        name: 'EventImage',
        value: 'true'
      });
      await createNodeField({
        node: fileNode,
        name: 'name',
        value: event.name
      });
    } catch (error) {
      console.warn('error creating node', error);
    }
  }
};
Run Code Online (Sandbox Code Playgroud)