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

Image placeholder does not respect objectFit property #30033

Closed
matteosailogy opened this issue Oct 18, 2021 · 8 comments
Closed

Image placeholder does not respect objectFit property #30033

matteosailogy opened this issue Oct 18, 2021 · 8 comments
Assignees
Labels
Image (next/image) Related to Next.js Image Optimization.

Comments

@matteosailogy
Copy link

What version of Next.js are you using?

11.1.0

What version of Node.js are you using?

14.17.0

What browser are you using?

Chrome

What operating system are you using?

macOS

How are you deploying your application?

next start

Describe the Bug

When I use the Image component to render an image with layout=fill and objectFit=contain property, it does it well when the image has been loaded (image is adapting into parent container), but when I set placeholder=blur I see blurred image filling the whole container instead of being contained (image ratio is same as original)

Expected Behavior

I'm expecting to see objectFit and objectPosition props to blurDataURL image as well

To Reproduce

Here is the code sample:
<Image src="https://assets.imgix.net/setup/serving-swimmer.jpg?w=7000" alt="Image test" layout="fill" objectFit="contain" objectPosition="center" placeholder="blur" blurDataURL="https://assets.imgix.net/setup/serving-swimmer.jpg?w=10" />
You can find a sandbox running sample here. If your connection is too good, please increase the w=7000 value in src to increase the image size
https://codesandbox.io/s/image-placeholder-object-fit-contain-70h5q?file=/pages/index.js

@matteosailogy matteosailogy added the bug Issue was opened via the bug report template. label Oct 18, 2021
@vulture990
Copy link

I had that issue too once

@timneutkens timneutkens added the Image (next/image) Related to Next.js Image Optimization. label Oct 31, 2021
@styfle styfle self-assigned this Nov 16, 2021
@styfle styfle added this to the 12.0.5 milestone Nov 16, 2021
@styfle
Copy link
Member

styfle commented Nov 16, 2021

Seems like other styles are not applied either such as border-radius #18858 (comment)

@styfle styfle added kind: bug and removed bug Issue was opened via the bug report template. labels Nov 16, 2021
@timneutkens timneutkens removed this from the 12.0.5 milestone Nov 17, 2021
@kara kara assigned atcastle and unassigned kara Jan 31, 2022
@styfle
Copy link
Member

styfle commented Mar 2, 2022

This should be fixed once we land #34339 and the style prop can be used instead of the objectFit prop.

@kirkas
Copy link

kirkas commented Mar 17, 2022

Also experiencing that issue.

Even if "raw" eventually solves a particular use case, it still means that blur area will fit the entire parent width/height when using layout="fill" & objectFit="contain"

@grazianodev
Copy link

Experiencing this too and found that applying an aspect ratio to the image's parent helps, something like:

<div className={ styles.ImageContainer } style={{ aspectRatio: `${image.width}/${image.height}` }}>
    <Image 
        src={ image.src } 
        layout="fill" 
        objectFit="contain" 
        placeholder="blur" 
        blurDataURL={ image.placeholder }
    />
</div>

@joshuabaker
Copy link
Contributor

Looks to have been resolved in #26590

@balazsorban44
Copy link
Member

Closing because of the suggestion above. If you still think it's an issue, please open a new one with a fresh reproduction (using next@canary). Thanks!

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Image (next/image) Related to Next.js Image Optimization.
Projects
None yet
Development

No branches or pull requests

10 participants