Next.js Discord

Discord Forum

Weird Image behavior

Answered
jsoneaday posted this in #help-forum
Open in Discord
I have this code for my Image tag.
<Image
      src={`/api/work/image/${id}/main`}
      alt="Description"
      objectFit="contain"
      layout="fill"
    />
And I have a div parent set to 100px. As the screenshot shows the asian girl pic is displaying with two distinct dimensions. I've confirmed I only have one image of that. What is the issue?
Answered by jsoneaday
I ended up switching to this
<Image
      src={`/api/work/image/${id}/main`}
      className="rounded-xl"
      alt="Description"
      width={300}
      height={300}
    />
and then wrapping it inside a parent
<div style={{ width: "300px", height: "auto" }}>
          <WorkImage id={work.id} />
        </div>
View full answer

2 Replies

I ended up switching to this
<Image
      src={`/api/work/image/${id}/main`}
      className="rounded-xl"
      alt="Description"
      width={300}
      height={300}
    />
and then wrapping it inside a parent
<div style={{ width: "300px", height: "auto" }}>
          <WorkImage id={work.id} />
        </div>
Answer