Skip to content

Commit bc5c2ed

Browse files
authored
Merge pull request #18 from uploadcare/feat/blur-image-url
Generate `blurDataURL` when `placeholder=blur` enabled
2 parents 1d585f3 + d3b6f0a commit bc5c2ed

25 files changed

+1111
-3505
lines changed

.gitignore

Lines changed: 4 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,108 +1,5 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
yarn-debug.log*
6-
yarn-error.log*
7-
lerna-debug.log*
8-
9-
# Diagnostic reports (https://nodejs.org/api/report.html)
10-
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11-
12-
# Runtime data
13-
pids
14-
*.pid
15-
*.seed
16-
*.pid.lock
17-
18-
# Directory for instrumented libs generated by jscoverage/JSCover
19-
lib-cov
20-
21-
# Coverage directory used by tools like istanbul
22-
coverage
23-
*.lcov
24-
25-
# nyc test coverage
26-
.nyc_output
27-
28-
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29-
.grunt
30-
31-
# Bower dependency directory (https://bower.io/)
32-
bower_components
33-
34-
# node-waf configuration
35-
.lock-wscript
36-
37-
# Compiled binary addons (https://nodejs.org/api/addons.html)
38-
build/Release
39-
40-
# Dependency directories
41-
node_modules/
42-
jspm_packages/
43-
44-
# TypeScript v1 declaration files
45-
typings/
46-
47-
# TypeScript cache
48-
*.tsbuildinfo
49-
50-
# Optional npm cache directory
51-
.npm
52-
53-
# Optional eslint cache
54-
.eslintcache
55-
56-
# Microbundle cache
57-
.rpt2_cache/
58-
.rts2_cache_cjs/
59-
.rts2_cache_es/
60-
.rts2_cache_umd/
61-
62-
# Optional REPL history
63-
.node_repl_history
64-
65-
# Output of 'npm pack'
66-
*.tgz
67-
68-
# Yarn Integrity file
69-
.yarn-integrity
70-
71-
# dotenv environment variables file
1+
node_modules
2+
build
3+
.github
4+
.husky
725
.env
73-
.env.test
74-
75-
# parcel-bundler cache (https://parceljs.org/)
76-
.cache
77-
78-
# Next.js build output
79-
.next
80-
81-
# Nuxt.js build / generate output
82-
.nuxt
83-
# dist
84-
85-
# Gatsby files
86-
.cache/
87-
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88-
# https://nextjs.org/blog/next-9-1#public-directory-support
89-
# public
90-
91-
# vuepress build output
92-
.vuepress/dist
93-
94-
# Serverless directories
95-
.serverless/
96-
97-
# FuseBox cache
98-
.fusebox/
99-
100-
# DynamoDB Local files
101-
.dynamodb/
102-
103-
# TernJS port file
104-
.tern-port
105-
106-
# Project-secific.
107-
coverage
108-

README.md

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ The package helps you use the Uploadcare's transformation and CDN services from
1212

1313
It provides the `uploadcareLoader` function, which you can use as [a custom loader for the Next's Image component](https://nextjs.org/docs/api-reference/next/image#loader), and the `UploadcareImage` component with the custom loader enabled by default.
1414

15-
1615
* [Demo](#demo)
1716
* [Dependencies](#dependencies)
1817
* [Installation](#installation)
1918
* [Configuration](#configuration)
2019
* [Usage](#usage)
20+
* [Props](#props)
2121
* [Notes](#notes)
2222
* [Known Issues](#known-issues)
2323
* [Links](#links)
@@ -28,7 +28,7 @@ Look at the demo [here][demo-link].
2828

2929
## Dependencies
3030

31-
The only dependency is Next.js >= 10.0.5.
31+
The only dependency is Next.js >= 10.0.5.
3232

3333
## Installation
3434

@@ -108,7 +108,7 @@ The `UploadcareImage` component supports the same parameters as the Next `Image`
108108
import Image from 'next/image';
109109
import { uploadcareLoader } from '@uploadcare/nextjs-loader';
110110

111-
<Image
111+
<Image
112112
alt="A test image"
113113
src="https://your-domain/image.jpg"
114114
width="400"
@@ -122,7 +122,7 @@ import { uploadcareLoader } from '@uploadcare/nextjs-loader';
122122

123123
In that case, you may not need the `loader: "custom"` setting in your `next.config.js`.
124124

125-
1. Install [next-image-loader](https://www.npmjs.com/package/next-image-loader) and enable it as described in its README.
125+
1. Install [next-image-loader](https://www.npmjs.com/package/next-image-loader) and enable it as described in its README.
126126

127127
2. Create `image-loader.config.js` in the project root (in the same directory as `next.config.js`)
128128
and add this code to it:
@@ -140,7 +140,7 @@ imageLoader.loader = uploadcareLoader;
140140
```tsx
141141
import Image from 'next/image';
142142

143-
<Image
143+
<Image
144144
alt="A test image"
145145
src="https://your-domain/image.jpg"
146146
width="400"
@@ -155,7 +155,7 @@ Please note that you can still use any other loader for a separate image like th
155155
import Image from 'next/image';
156156
import anotherLoader from '[another-loader-project-name]';
157157

158-
<Image
158+
<Image
159159
alt="A test image"
160160
src="https://your-domain/image.jpg"
161161
width="400"
@@ -167,15 +167,71 @@ import anotherLoader from '[another-loader-project-name]';
167167

168168
where `anotherLoader` will be used instead of the Uploadcare loader for this particular image.
169169

170+
## Props
171+
172+
### `placeholder` and `blurDataURL`
173+
174+
[Read Next.js Image Component docs](https://nextjs.org/docs/api-reference/next/image#placeholder) about `placeholder` and `blurDataURL`.
175+
176+
There are two possible use cases:
177+
178+
1. [When `src` is a string](#when-src-is-a-string)
179+
2. [When `src` is a static import](#when-src-is-a-static-import)
180+
181+
#### When `src` is a string
182+
183+
This options is available for the `UploadcareImage` component only. It won't work when you're using custom loader directly.
184+
185+
If you pass `placeholder="blur"` to the `UploadcareImage` component, it will generate `blurDataURL` with the URL of the placeholder image (not base64) and use it as a placeholder. You can override `blurDataURL`.
186+
187+
188+
```tsx
189+
190+
```jsx
191+
<UploadcareImage
192+
alt="A test image"
193+
src="https://your-domain/image.jpg"
194+
width="400"
195+
height="300"
196+
quality="80"
197+
placeholder="blur"
198+
/>
199+
```
200+
201+
#### When `src` is a static import
202+
203+
You can use both `UploadcareImage` and `Image` component with custom loader. In this case Next.js will generate base64 encoded image for `blurDataURL` automatically during build time.
204+
205+
```jsx
206+
import staticImage from 'image.jpg'
207+
208+
<UploadcareImage
209+
alt="A test image"
210+
src={staticImage}
211+
width="400"
212+
height="300"
213+
quality="80"
214+
placeholder="blur"
215+
/>
216+
```
217+
170218
## Notes
171219

172220
- If you have jpegs larger than 3000px and you want loader to resize them up to 5000px, you need to pass filename with `jpeg` or `jpg` extension to the src url. See [Output image dimensions docs](https://uploadcare.com/docs/transformations/image/#dimensions) for more details. When no filename provided, we'll treat the image as non-jpeg and can resize it up to 3000px only.
173221

174222
- If you pass a local image url, the loader returns it AS IS if the app is run in the development mode or if the `NEXT_PUBLIC_UPLOADCARE_APP_BASE_URL` is not set.
175223

224+
- Next.js Image component allows numeric only `quality` value. Uploadcare CDN supports string-based quality only (see [our docs](https://uploadcare.com/docs/transformations/image/compression/#operation-quality)). So numeric quality values will be mapped onto string ones using the following intervals:
225+
226+
- 1-38 - lightest
227+
- 39-70 - lighter
228+
- 71-80 - normal
229+
- 81-88 - better
230+
- 89-100 - best
231+
176232
## Known Issues
177233

178-
**Issue 1:** Console warning like this:
234+
**Issue 1:** Console warning like this:
179235
> Image with src "${src}" has a "loader" property that does not implement width. Please implement it or use the "unoptimized" property instead.
180236
Read more: https://nextjs.org/docs/messages/next-image-missing-loader-width
181237

@@ -191,5 +247,5 @@ Next checks whether the image url which loader generates has the exact value whi
191247
[test-status-img]: https://github.com/uploadcare/nextjs-loader/actions/workflows/test-and-lint.yml/badge.svg
192248
[npm-img]: https://img.shields.io/npm/v/@uploadcare/nextjs-loader.svg
193249
[npm-link]: https://www.npmjs.com/package/@uploadcare/nextjs-loader
194-
[demo-link]: https://uploadcare-nextjs-loader.vercel.app/
250+
[demo-link]: https://uploadcare-nextjs-loader.netlify.app/
195251
[uploadcare-transformation-image-compression-docs]: https://uploadcare.com/docs/transformations/image/compression/?utm_source=github&utm_campaign=nextjs-loader

build/components/UploadcareImage.d.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

build/components/UploadcareImage.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

build/index.d.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

build/index.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

build/utils/constants.d.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

build/utils/constants.js

Lines changed: 0 additions & 8 deletions
This file was deleted.

build/utils/helpers.d.ts

Lines changed: 0 additions & 37 deletions
This file was deleted.

0 commit comments

Comments
 (0)