Unverified Commit 2967fe1d authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Update docs on static image imports (#26211)



Incorporates some of the feedback we've had about this doc.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes
parent 82bad10a
...@@ -31,14 +31,13 @@ To add an image to your application, import the [`next/image`](/docs/api-referen ...@@ -31,14 +31,13 @@ To add an image to your application, import the [`next/image`](/docs/api-referen
```jsx ```jsx
import Image from 'next/image' import Image from 'next/image'
import profilePic from '../public/me.png'
function Home() { function Home() {
return ( return (
<> <>
<h1>My Homepage</h1> <h1>My Homepage</h1>
<Image <Image
src={profilePic} src="/me.png"
alt="Picture of the author" alt="Picture of the author"
width={500} width={500}
height={500} height={500}
...@@ -51,6 +50,39 @@ function Home() { ...@@ -51,6 +50,39 @@ function Home() {
export default Home export default Home
``` ```
## Image Imports
You can `import` images that live in your project. (Note that `require` is not supported—only `import`.)
With direct `import`s, `width`, `height`, and `blurDataURL` will be automatically provided to the image component. Alt text is still needed separately.
```js
import Image from 'next/image'
import profilePic from '../public/me.png'
function Home() {
return (
<>
<h1>My Homepage</h1>
<Image
src={profilePic}
alt="Picture of the author"
// width={500} automatically provided
// height={500} automatically provided
// blurDataURL="data:..." automatically provided
// Optionally allows to add a blurred version of the image while loading
// placeholder="blur"
/>
<p>Welcome to my homepage!</p>
</>
)
}
```
For dynamic images you have to provide `width`, `height` and `blurDataURL` manually.
## Properties
[View all properties](/docs/api-reference/next/image.md) available to the `next/image` component. [View all properties](/docs/api-reference/next/image.md) available to the `next/image` component.
## Configuration ## Configuration
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment