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

时间:2018-11-16 14:42:06

标签: javascript reactjs graphql gatsby

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

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

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

从1000幅图像来看,似乎只有1幅图像很麻烦,并返回错误

Errors:
  icc_transform: no input profile
  vips_colourspace: no known route from 'cmyk' to 'srgb'

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

我如何

  1. 修正sharp所显示的错误,以便可以处理图像吗?或者,
  2. 在处理filter期间返回此错误的
  3. createRemoteFileNode个图像,或
  4. catch (error)中跳过麻烦的图像,或
  5. 其他任何想法/解决方案
createRemoteFileNode中的

gatsby-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);
    }
  }
};

0 个答案:

没有答案