Repository: gatsbyjs/gatsby
File: packages/gatsby-plugin-sharp/src/process-file.js (JavaScript)

Code before:
      // set, check first before trying to round them.
      let roundedHeight = transformArgs.height
      if (roundedHeight) {
        roundedHeight = Math.round(roundedHeight)
      }

      let roundedWidth = transformArgs.width
      if (roundedWidth) {
        roundedWidth = Math.round(roundedWidth)
      }

      clonedPipeline
        .resize(roundedWidth, roundedHeight, {
          position: transformArgs.cropFocus,
          fit: transformArgs.fit,
          background: transformArgs.background,
        })
        .png({
          compressionLevel: transformArgs.pngCompressionLevel,
          adaptiveFiltering: false,
          force: transformArgs.toFormat === `png`,
        })
        .tiff({
          quality: transformArgs.quality,
          force: transformArgs.toFormat === `tiff`,
        })

      // jpeg
      if (!options.useMozJpeg) {
        clonedPipeline = clonedPipeline.jpeg({
          quality: transformArgs.jpegQuality || transformArgs.quality,
          progressive: transformArgs.jpegProgressive,
          force: transformArgs.toFormat === `jpg`,
        })
      }

      // grayscale
      if (transformArgs.grayscale) {
        clonedPipeline = clonedPipeline.grayscale()
      }

      // rotate
      if (transformArgs.rotate && transformArgs.rotate !== 0) {
        clonedPipeline = clonedPipeline.rotate(transformArgs.rotate)
      }

      // duotone
      if (transformArgs.duotone) {
        clonedPipeline = await duotone(
          transformArgs.duotone,
          transformArgs.toFormat,

Review comment (suggestion):
I think this should be the other way around?

I've recently noticed that my output from processing with `sharp` without gatsby differed in quality and filesize for some reason. Came across your PR here, and now it makes sense that it's due to the double compression as you've found here, but imagemin is the culprit.

It reduces filesize from 16.5KiB to 15.6KiB, but introduces some notable artifacts, both would be running at quality of 75. When removing the `sharp` processing that you've done here, just with imagemin instead, the output filesize is 17.1KiB for my test file and the quality is not as good.

Code after:
      let roundedHeight = transformArgs.height
      if (roundedHeight) {
        roundedHeight = Math.round(roundedHeight)
      }

      let roundedWidth = transformArgs.width
      if (roundedWidth) {
        roundedWidth = Math.round(roundedWidth)
      }

      clonedPipeline
        .resize(roundedWidth, roundedHeight, {
          position: transformArgs.cropFocus,
          fit: transformArgs.fit,
          background: transformArgs.background,
        })
        .png({
          compressionLevel: transformArgs.pngCompressionLevel,
          adaptiveFiltering: false,
          force: transformArgs.toFormat === `png`,
        })
        .webp({
          quality: transformArgs.webpQuality || transformArgs.quality,
          force: transformArgs.toFormat === `webp`,
        })
        .tiff({
          quality: transformArgs.quality,
          force: transformArgs.toFormat === `tiff`,
        })

      // jpeg
      if (!options.useMozJpeg) {
        clonedPipeline = clonedPipeline.jpeg({
          quality: transformArgs.jpegQuality || transformArgs.quality,
          progressive: transformArgs.jpegProgressive,
          force: transformArgs.toFormat === `jpg`,
        })
      }

      // grayscale
      if (transformArgs.grayscale) {
        clonedPipeline = clonedPipeline.grayscale()
      }

      // rotate
      if (transformArgs.rotate && transformArgs.rotate !== 0) {
        clonedPipeline = clonedPipeline.rotate(transformArgs.rotate)
      }

      // duotone
      if (transformArgs.duotone) {