-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[gatsby-remark-images] Tall images cannot be restricted by maxHeight #15241
Comments
The What would be needed here is support for |
Hiya! This issue has gone quiet. Spooky quiet. 👻 We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open! As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contributefor more information about opening PRs, triaging issues, and contributing! Thanks for being a part of the Gatsby community! 💪💜 |
Hey again! It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing! Thanks again for being part of the Gatsby community! |
For anyone stumbling on this like me. My solution was to add a wrapper style to the image container to restrict it's height and add a link to a scss file in my template file to add I'd love to know if there's a better solution for this now? This works for me though. .gatsby-resp-image-image {
object-fit: contain;
} in {
resolve: 'gatsby-remark-images',
options: {
...
wrapperStyle: () => 'max-height: 80vh;',
backgroundColor: 'transparent'
}
}, If you don't also set transparent for the background color you'll also end up with a large white box surrounding your images. |
For anyone solving this issue using @daniebker's solution, you may also run into a problem where the low-resolution placeholder I've been able to temporarily fix this issue by adding the //gatsby-config.js
{
resolve: `gatsby-remark-images`,
options: {
wrapperStyle: () => 'max-height: 60vh; ',
disableBgImage: true,
...
} |
@jbierfeldt I've found that you can specify Might be a little late now... |
For those who still struggling with this, I've found a pretty reasonable workaround: //gatsby-config.js
{
resolve: `gatsby-remark-images`,
options: {
maxWidth: 1000,
wrapperStyle: image =>
`max-width: clamp(200px, calc(${image.aspectRatio} * 80vh), 1000px);`,
},
} I had to configure maxWidth twice to generate the right size images. 'Clamp' is not yet supported in all browsers, but has a good global usage percentage: https://caniuse.com/?search=clamp As a bonus, for those who, like me, wanted to limit the width OR the height (in case of portrait images), I came up with this more specific version: //gatsby-config.js
{
resolve: `gatsby-remark-images`,
options: {
maxWidth: 1000,
wrapperStyle(image) {
let maxImageWidth;
if (image.aspectRatio < 1) maxImageWidth = image.aspectRatio * 1000;
else maxImageWidth = 1000;
return `max-width: clamp(200px, calc(${
image.aspectRatio
}* 80vh), ${
Math.round(maxImageWidth * 10) / 10
}px); max-height: 1000px;`;
},
},
},
} Hope this help someone! 😃 |
Summary
Tall images cannot be restricted by maxHeight. These images end up taking the whole width of the screen and are too tall.
Basic example
Proposed API:
Motivation
I have an iPhone screenshot I want to add to my blog. I have it rendering properly, but there is no simple way to shrink it down to a reasonable size without also shrinking the wider images.
The text was updated successfully, but these errors were encountered: