Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remark-images blows up images to 100% width and ignores ppi #1987

Merged
merged 4 commits into from
Sep 1, 2017

Conversation

bripkens
Copy link
Contributor

As discussed in #1982, changes the following:

  • do not stretch images to 100% width
  • account for different DPIs / PPIs when presenting images

I still have to validate this in more detail, mostly the srcset attribute and how it is working. The resizing behavior seems to work fine though. Open for early feedback should you find a minute @fk / @KyleAMathews.

Quick video of the resizing / fallback behavior: https://www.youtube.com/watch?v=hDgrbNcCi1I&feature=youtu.be

Fixes #1982

@bripkens
Copy link
Contributor Author

Totally forgot that there is an auto deploy for Gatsby. I probably didn't have to record a video :)

@gatsbybot
Copy link
Collaborator

Deploy preview ready!

Built with commit 8c67eb9

https://deploy-preview-1987--gatsbygram.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Aug 31, 2017

Deploy preview ready!

Built with commit 27dee8f

https://deploy-preview-1987--gatsbygram.netlify.com

Copy link
Contributor

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -363,6 +363,13 @@ async function responsiveSizes({ file, args = {} }) {
options.sizes = `(max-width: ${options.maxWidth}px) 100vw, ${options.maxWidth}px`
}

// Account for images with a high pixel density. We assume that these types
// of images are intended to be used as high resolution ("retina") images.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps change the comment to:

"We assume that these types of images are intended to be displayed at their native resolution."

The sentence as it reads now is confusing because we always aim to provide users with retina-class devices a high resolution image. The fix is to avoid expanding the images themselves beyond their original width/height.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Updated the comment!

@@ -363,6 +363,13 @@ async function responsiveSizes({ file, args = {} }) {
options.sizes = `(max-width: ${options.maxWidth}px) 100vw, ${options.maxWidth}px`
}

// Account for images with a high pixel density. We assume that these types
// of images are intended to be used as high resolution ("retina") images.
const { width, height, density } = await sharp(file.absolutePath).metadata()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be much more efficient to get the metadata from the previous sharp instance for the file. There's costs to making this call as it has to read the image off disk, do analysis, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which previous sharp instance do you mean? AFAIK this is the first one. I could only try to pass this instance down to gatsby-plugin-sharp.

@KyleAMathews
Copy link
Contributor

Videos are always super nice though :-)

@bripkens
Copy link
Contributor Author

bripkens commented Sep 1, 2017

Videos are always super nice though :-)

Then I'll keep them coming :). Here is a new one which shows how the browser is selecting larger image variants while taking pixel ratio into account (I had no idea it would do this automatically, but I suppose this is why the width definition in srcset is done in w units):

https://www.youtube.com/watch?v=pRP6woILpsE&feature=youtu.be

As far as I am concerned, this PR is now doing what we discussed. I (currently) have no more open action points.

@bripkens
Copy link
Contributor Author

bripkens commented Sep 1, 2017

Tested my changes also in my company's docs. Looking much better now!

@bripkens
Copy link
Contributor Author

bripkens commented Sep 1, 2017

Found something which looks suspicious in our docs. Might be that I have overlooked a certain sizing case. Will update once I have analyzed this. Pls don't merge yet.

@bripkens
Copy link
Contributor Author

bripkens commented Sep 1, 2017

Okay, the suspicious behavior was actually caused by an image that got replaced (we had a few broken PNGs in our docs). I was confused by that. These changes work as intended 👍.

@KyleAMathews KyleAMathews merged commit 4f8c27a into gatsbyjs:master Sep 1, 2017
@KyleAMathews
Copy link
Contributor

Nice! Thanks for taking this from issue to very nice PR!

@KyleAMathews
Copy link
Contributor

Deploy preview failed.

Built with commit 27dee8f

https://app.netlify.com/sites/using-glamor/deploys/59a9d94b0752d016b2164dc3

@bripkens bripkens deleted the fix-1982 branch September 2, 2017 15:29
@bripkens
Copy link
Contributor Author

bripkens commented Sep 2, 2017

Sorry for that. I thought that npm run test includes linting. My bad :/

@gausie
Copy link

gausie commented Sep 30, 2017

Having some trouble with this patch, as described in #2292

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants