question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<Image/> causing image degradation

See original GitHub issue

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

  Node: 16.13.2
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant packages:
  next: 12.2.3-canary.12
  eslint-config-next: 11.1.2
  react: 18.2.0
  react-dom: 18.2.0

What browser are you using? (if relevant)

Chrome 103.0.5060.114

How are you deploying your application? (if relevant)

No response

Describe the Bug

Using the <Image/> tag and adding a specific width & height to an image that is much larger than that and adding the CSS property object-fit: cover; causes the image’s resolution to degrade by a lot. When we switch to the normal HTML tag with the same image, width, and CSS, the image is displayed fine in full resolution.

Expected Behavior

The image quality should not degrade like this and it should keep full resolution

Link to reproduction

https://codesandbox.io/s/romantic-vaughan-j332co?file=/pages/index.tsx

To Reproduce

Use <Image/> to display an image, style it with object-fit: cover (I used tailwindcss to achieve this here) and put a width and height that’s smaller than the original image

            <Image
              src={"/image.png"}
              className="object-cover"
              width={300}
              height={550}
            />

Check link for comparison with <img/> with the same styling

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
iljamulderscommented, Jul 20, 2022

I think you are changing the aspect ratio of the image with your width & height?

use layout fill with objectFit cover

Docs: https://nextjs.org/docs/api-reference/next/image#objectfit Demo: https://image-component.nextjs.gallery/layout-fill

import step2banner from "../public/step2banner.png";

<Image
    alt="Step 2 banner"
    layout="fill"
    objectFit="cover"
    src={step2banner}
/>

https://codesandbox.io/s/proud-sea-3oo17s

1reaction
A7Ucommented, Jul 19, 2022

Just tried quality={100}, and the extremely bad quality is still the same, so that’s not the issue sadly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Degraded Image - an overview | ScienceDirect Topics
The input to the processing system is a degraded image (or set of images or video signal) such as blurred image, noisy image,...
Read more >
What are image degradation and restoration models?
Image degradation is the loss of image quality for a variety of reasons. When there is image deterioration, the quality of the image...
Read more >
Image Restoration - Degradation Model
The purpose of image restoration is to "compensate for" or "undo" defects which degrade an image. Degradation comes in many forms such as...
Read more >
A Basic Introduction to Preventing Jpg Image Degradation
This issue of JPG image degradation is true for small images with low resolution for the Web - and equally true as well...
Read more >
Sources of Image Degradation in Fundamental and Harmonic ...
First, the sources of image degradation in the fundamental images are primarily due to phase aberration and reverberation in near-field abdominal structures.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found