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

feat(*): add options fit and background to image sharp #13078

Merged
merged 5 commits into from
Apr 11, 2019
Merged

feat(*): add options fit and background to image sharp #13078

merged 5 commits into from
Apr 11, 2019

Conversation

VGoose
Copy link
Contributor

@VGoose VGoose commented Apr 3, 2019

Description

gatsby-plugin-sharp

  • add fit and background options to control cropping when using fluid

gatsby-transformer-sharp

  • add new ImageFitType type and add fit and background to fluidNodeType args.

Related Issues

Addresses #12972.

Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

This is starting to look good! I added a few nits about the README.

Still need to test it myself but code looks 👌

yarn.lock Outdated Show resolved Hide resolved
packages/gatsby-plugin-sharp/README.md Outdated Show resolved Hide resolved
packages/gatsby-plugin-sharp/README.md Outdated Show resolved Hide resolved
@wardpeet wardpeet changed the title add fit and background options to fluid feat(*): add options fit and background to image sharp Apr 5, 2019
@wardpeet wardpeet added the status: awaiting author response Additional information has been requested from the author label Apr 5, 2019
@VGoose
Copy link
Contributor Author

VGoose commented Apr 5, 2019

Failing ci/circleci: starters_validate

npm ERR! code ENOAUDIT
npm ERR! audit Your configured registry (https://registry.npmjs.org/) does not support audit requests.

I'm not sure how to fix this, all tests pass locally for me.

@wardpeet wardpeet removed the status: awaiting author response Additional information has been requested from the author label Apr 11, 2019
Copy link
Contributor

@wardpeet wardpeet left a comment

Choose a reason for hiding this comment

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

This looks good to me! Let me this one before merging

@wardpeet wardpeet merged commit 494ad07 into gatsbyjs:master Apr 11, 2019
@gatsbot
Copy link

gatsbot bot commented Apr 11, 2019

Holy buckets, @VGoose — we just merged your PR to Gatsby! 💪💜

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (Currently we’ve got a couple t-shirts available, plus some socks that are really razzing our berries right now.)
  2. We just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. Accept the invite by visiting https://github.com/orgs/gatsbyjs/invitation. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If there’s anything we can do to help, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again!

@tremby
Copy link
Contributor

tremby commented Apr 11, 2019

This unfortunately doesn't quite cover the use case I had in mind.

In "contain" mode, with "maxWidth" and "maxHeight" both set, I was expecting the output images to still be the source image's aspect ratio, not forced to the ratio maxWidth:maxHeight and with a background colour applied.

Example:

  • Source images are various sizes and aspects. A particular one is 2000x1000 pixels (2:1) ratio. Another is 1000x2000 pixels (1:2 ratio).
  • We want to show them all in a grid of squares (1:1 ratio), but want to see the original aspects within those squares. Those squares are a presentation concern -- my HTML/CSS will deal with that. I just want suitably-sized images.
  • We request fluid images with maxHeight 200, maxWidth 200, contain mode.

I expected the output for these particular images to be 200x100 pixels (along with smaller and bigger versions for different size viewports and pixel densities, eg 100x50, 150x75, 300x150, 400x200) and 100x200 pixels (along with smaller and bigger versions): the original aspect ratios, but with the "canonical" size fitting within the 200x200 I specified as maximum.

But with this patch I get two 200x200 images with black bars baked in (along with smaller and bigger versions, all with black bars).

It looks like the background could be set to transparent so you don't get actual black bars, but you're still changing the aspect of the output image from the images' source aspects, which to me is undesirable. Imagine for example another scenario where instead of showing these images in a grid they're floating in a block of text, and you want the text to flow around them.

@VGoose
Copy link
Contributor Author

VGoose commented Apr 11, 2019

@tremby thanks for the clear example!

When I was making this PR I left inside and outside out because I didn't really understand the use case but now I think you're describing what inside is. I was also trying to keep my first PR small and so less prone to errors. I think this should be easy to add; I'll take a stab at it soon.

**Note for others who might read this: with contain, you can specify the backgroundColor and can make it any color or transparent to avoid the default black bars.

@tremby
Copy link
Contributor

tremby commented Apr 11, 2019

That's a really useful link.

Yes, what I'm looking for and would have expected for "contain" is what they call "inside". I expect there are valid use cases for both, and I see no reason to break from their terminology. :)

While I can't think of a use case for "outside" off the top of my head, I do imagine one exists!

@wardpeet
Copy link
Contributor

@tremby this is still a great addition and another pr could define those other 2 props. @VGoose mind taking this one? 😄

@VGoose
Copy link
Contributor Author

VGoose commented Apr 12, 2019

Yep! I'll submit a PR once it gets completed.

wardpeet added a commit that referenced this pull request Mar 10, 2020
Added `INSIDE` and `OUTSIDE` options for for gatsby-transformer-sharp. Here's a use case for inside [#13078 (comment)](#13078 (comment)).
This includes changing gatsby-image to use `contain` instead of `cover` for object-fit, which does not affect the existing fit options.
Updated documentation for gatsby-transformer-sharp to clarify the fit options and show that they are available for all three functions.

NOTE: This is an extension of PR #13393 by @VGoose , which was closed because he didn't have time to complete the work.


Co-authored-by: AnhVoMBP15 <[email protected]>
Co-authored-by: soundguy66 <[email protected]>
Co-authored-by: gatsbybot <[email protected]>
Co-authored-by: Ward Peeters <[email protected]>
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.

4 participants