prismic-gatsby: imageImgixParams not being honoured to prevent format conversion

Versions

  • gatsby-source-prismic: v4.2.0
  • gatsby-plugin-prismic-previews: not installed
  • node: v16.10.0

Reproduction

Store a PNG image in Prismic, use imageImgixParams to prevent conversion to JPEG.

Additional Details
Plugin configuraton:
    {
      resolve: 'gatsby-source-prismic',
      options: {
        repositoryName: process.env.PRISMIC_REPOSITORY_Name,
        accessToken: process.env.PRISMIC_ACCESS_TOKEN,
        customTypesApiToken: process.env.PRISMIC_CUSTOM_TYPES_API_TOKEN,
        typePrefix: process.env.PRISMIC_TYPE_PREFIX,
        lang: '*',
        imageImgixParams: {
          q: 100,
        },
      },
    },

GraphQL query (testing only):

query MyQuery {
  prismicModule {
    data {
      background_image {
        localFile {
          childImageSharp {
            original {
              src
            }
          }
        }
      }
    }
  }
}

Steps to reproduce

  1. Add an image to Prismic
  2. Configure gatsby-source-prismic without auto=formatt
  3. Check the file downloaded in the .cache folder

./caches/gatsby-source-prismic/xxxxx/xxx.png: JPEG image data, JFIF standard 1.01, resolution (DPI), density 72x72, segment length 16, progressive, precision 8, 1344x1058, frames 3

I have tried with auto=“compress”, auto=“” and no auto in th eplugin configuration, in all cases the file is downloaded as a JPEG.

The .cache/caches/gatsby-source-prismic/diskstore-*.json file contains:

“key”:“create-remote-file-node-headers-https://images.prismic.io/XXXX/xxx.png?auto=compress,format

What is expected?

The image should be downloaded as its original PNG to allow it to be converted efficiently with childImageSharp.

What is actually happening?

However, it’s always being downloaded to the .cache folder as a JPEG, meaning when it is converted back to PNG it is larger than expected and contains JPEG compression artefacts.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (7 by maintainers)

Most upvoted comments

I just saw you are on V4. Here is a migration guide to go from V4 to V5: https://prismic.io/docs/technologies/gatsby-prismic-v4-to-v5

It should be fairly quick to upgrade. v5.0.1 also includes the ability to opt-in to all file downloads. If you don’t want to list all of your files individually like it is shown in the migration guide, you can provide this instead:

// Example gatsby-config.js file

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-source-prismic',
      options: {
        // Alongside your other options...
        shouldDownloadFiles: true
      }
    }
  ]
}