Skip to content

Commit

Permalink
Update docs on static image imports (#26211)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
timneutkens authored Jun 16, 2021
1 parent 82bad10 commit 2967fe1
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions docs/basic-features/image-optimization.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ To add an image to your application, import the [`next/image`](/docs/api-referen

```jsx
import Image from 'next/image'
import profilePic from '../public/me.png'

function Home() {
return (
<>
<h1>My Homepage</h1>
<Image
src={profilePic}
src="/me.png"
alt="Picture of the author"
width={500}
height={500}
Expand All @@ -51,6 +50,39 @@ function 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.

## Configuration
Expand Down

0 comments on commit 2967fe1

Please sign in to comment.