Skip to main content
BlogWeb Development

Ship Codex-Generated Images Through Next.js Image

Ship a Codex-generated hero with Next.js Image. Choose responsive sizes, preserve the important crop and verify the file the browser actually requests.

Matthews Wong

Software Engineer

December 20262 min read
Ship Codex-Generated Images Through Next.js Image

Key Takeaway

A Next.js workflow for Codex-generated imagery preserves the selected original, creates a site-ready file and serves it with a responsive Image configuration. Verify the actual bytes and the browser’s layout at more than one width. This keeps an attractive hero from becoming an unnecessarily heavy mobile download.

Where should the file live?

Move a copy into a named assets directory in the repo. Choose a filename that describes the subject and usage. Save the original generation output separately while the app references the selected deployment file.

How should width and height be set?

Read the actual dimensions of the exported image. Use dimensions or a properly sized fill container as the Next.js Image documentation describes. Inspect surrounding layout while the network is throttled so a missing reserved area is visible.

Why does the sizes prop affect cost?

It tells the browser how wide the rendered image is expected to be at different viewport widths. Give it a value derived from the actual CSS layout. In DevTools, check which resource the browser selected at a narrow width.

How can you preserve the important crop?

Open the page at its narrowest supported width and inspect the focal point. Use the intended object position or a separate art-directed source when the composition requires it. Compare the screenshot to the original illustration brief.

What should be measured in the browser?

Record selected resource URL, transferred bytes and what happened to layout when it loaded. Compare another viewport on the same build. A smaller file can still disappoint if the browser downloads the largest candidate or shows a visibly broken crop.

import Image from "next/image";

<Image
  src="/images/blog/inline/codex-imagegen-bicycle-workshop.jpg"
  alt="A mechanic adjusting a bicycle derailleur"
  width={1200}
  height={800}
  sizes="(max-width: 767px) 100vw, 50vw"
  className="h-full w-full object-cover object-[65%_center]"
/>

How should an updated image be rolled out?

Use an intentional filename for a materially different asset and update all references in the same patch. Check card and detail routes if they share that asset. Save the mobile screenshot as evidence that the new file still works in its narrowest placement.

FAQ

Frequently Asked Questions

Short answers to what readers ask most about this topic.

Where should the file live?

Move a copy into a named assets directory in the repo. Choose a filename that describes the subject and usage. Save the original generation output separately while the app references the selected deployment file.

How should width and height be set?

Read the actual dimensions of the exported image. Use dimensions or a properly sized fill container as the Next.js Image documentation describes. Inspect surrounding layout while the network is throttled so a missing reserved area is visible.

Why does the sizes prop affect cost?

It tells the browser how wide the rendered image is expected to be at different viewport widths. Give it a value derived from the actual CSS layout. In DevTools, check which resource the browser selected at a narrow width.

How can you preserve the important crop?

Open the page at its narrowest supported width and inspect the focal point. Use the intended object position or a separate art-directed source when the composition requires it. Compare the screenshot to the original illustration brief.

What should be measured in the browser?

Record selected resource URL, transferred bytes and what happened to layout when it loaded. Compare another viewport on the same build. A smaller file can still disappoint if the browser downloads the largest candidate or shows a visibly broken crop.