Skip to content

Issue with gatsby-image : generated images are larger than original and worse in quality #14279

Closed
@dragonflypl

Description

@dragonflypl

Summary

I started to use gatsby-image to optimize images.

It happens for all my images. My configuration is :

  • plugins with no params:
    `gatsby-plugin-sharp`,
    `gatsby-transformer-sharp`
  • this is the query (version with hardcoded image name):
const query = graphql`
  query {
    allFile(filter: { absolutePath: { regex: "/images/folio/thumbs/biblioteka-uek-1/i" } }) {
      edges {
        node {
          name
          childImageSharp {
            fluid(maxWidth: 400, quality: 100) {
              ...GatsbyImageSharpFluid
            }
          }
        }
      }
    }
  }
`;

export default () => useStaticQuery(query).allFile.edges.map(x => x.node);

Sample output is:

{
  "data": {
    "allFile": {
      "edges": [
        {
          "node": {
            "name": "biblioteka-uek-1",
            "childImageSharp": {
              "fluid": {
                "aspectRatio": 1.4150943396226414,
                "src": "/static/27105dc2b375f80284a4aa9f890478ef/3ff6e/biblioteka-uek-1.jpg",
                "srcSet": "/static/27105dc2b375f80284a4aa9f890478ef/1cf29/biblioteka-uek-1.jpg 100w,\n/static/27105dc2b375f80284a4aa9f890478ef/b5b92/biblioteka-uek-1.jpg 200w,\n/static/27105dc2b375f80284a4aa9f890478ef/3ff6e/biblioteka-uek-1.jpg 400w,\n/static/27105dc2b375f80284a4aa9f890478ef/5e4f2/biblioteka-uek-1.jpg 600w,\n/static/27105dc2b375f80284a4aa9f890478ef/d47f1/biblioteka-uek-1.jpg 800w,\n/static/27105dc2b375f80284a4aa9f890478ef/86173/biblioteka-uek-1.jpg 1200w",
                "sizes": "(max-width: 400px) 100vw, 400px",
                "originalImg": "/static/27105dc2b375f80284a4aa9f890478ef/86173/biblioteka-uek-1.jpg",
                "originalName": "biblioteka-uek-1.jpg",
                "presentationWidth": 400,
                "presentationHeight": 283
              }
            }
          }
        }
      ]
    }
  }
}

and usage <Img fluid={thumb.childImageSharp.fluid} />

Why is that?

Activity

changed the title [-]Issue with gatsby-image : generated images are larger than original[/-] [+]Issue with gatsby-image : generated images are larger than original and worse in quality[/+] on May 23, 2019
KyleAMathews

KyleAMathews commented on May 23, 2019

@KyleAMathews
Contributor

We don't recommend using quality 100 as that (as you found out) generates very large images.

50-75 is generally a good range (we default to 50).

How wide is the container you're showing the images? Perhaps maxWidth should be larger?

dragonflypl

dragonflypl commented on May 23, 2019

@dragonflypl
Author

Indeed, max width should be slightly larger as in 2 col layout image was stretched.

I don't quite get it with quality param... I would like to preserve an image's quality and only have it resized. What config should I use?

DSchau

DSchau commented on May 23, 2019

@DSchau
Contributor

@dragonflypl the idea is that because you're already dealing with a lossy image (.jpg) that we can optimize even further, resulting in a smaller (by file-size) image that is generally visually indistinguishable to the end user.

Think of it as analogous to a compiler optimizing code. The code will still run the same way (as far as the end user is concerned) but it will be optimized, smaller, and perhaps even more efficient; so to are gatsby's image transformations and optimizations.

dragonflypl

dragonflypl commented on May 23, 2019

@dragonflypl
Author

I've used 500 width + quality 75. Looks better in terms of size and image quality, Thanks. Still, images are really not sharp and smoothed too much: https://2m2-optimized.dragonflypl.now.sh/portfolio/ .

Is there anything I can do to make it better?

DSchau

DSchau commented on May 23, 2019

@DSchau
Contributor

@dragonflypl looks fine to my eyes. Image quality is never going to be 1:1 (thus, a lossy image) but you want the optimization.

Original

Original

Optimized, Smaller Image

Optimized

Of course it won't look quite the same because it's a) compressed, and b) smaller, but I think the intent is clear here. Ship less bytes with optimized images that are visually mostly indistinguishable to the end user.

dragonflypl

dragonflypl commented on May 23, 2019

@dragonflypl
Author

Thanks for the explanation . Closing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @KyleAMathews@DSchau@dragonflypl

        Issue actions

          Issue with gatsby-image : generated images are larger than original and worse in quality · Issue #14279 · gatsbyjs/gatsby