wasm-image-optimization 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +28 -9
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -2,29 +2,34 @@
2
2
 
3
3
  # usage
4
4
 
5
- Sample of Cloudflare Workers
5
+ Next.js image optimization with Cloudflare
6
6
 
7
7
  ```ts
8
8
  import { optimizeImage } from 'wasm-image-optimization';
9
-
10
9
  export interface Env {}
11
10
 
12
11
  const handleRequest = async (
13
12
  request: Request,
14
- env: Env,
15
- ctx: ExecutionContext
13
+ _env: Env,
14
+ _ctx: ExecutionContext
16
15
  ): Promise<Response> => {
17
- const srcImage = await fetch(
18
- 'https://raw.githubusercontent.com/node-libraries/wasm-image-optimization/master/images/test01.jpg'
19
- ).then((res) => res.arrayBuffer());
16
+ const params = new URL(request.url).searchParams;
17
+ const url = params.get('url');
18
+ if (!url) {
19
+ return new Response('url is required', { status: 400 });
20
+ }
21
+ const width = params.get('w');
22
+ const quality = params.get('q');
23
+ const srcImage = await fetch(url).then((res) => res.arrayBuffer());
20
24
  const image = await optimizeImage({
21
25
  image: srcImage,
22
- width: 200,
23
- height: 200,
26
+ width: width ? parseInt(width) : undefined,
27
+ quality: quality ? parseInt(quality) : undefined,
24
28
  });
25
29
  return new Response(image, {
26
30
  headers: {
27
31
  'Content-Type': 'image/webp',
32
+ 'Cache-Control': 'public, max-age=31536000, immutable',
28
33
  },
29
34
  });
30
35
  };
@@ -33,3 +38,17 @@ export default {
33
38
  fetch: handleRequest,
34
39
  };
35
40
  ```
41
+
42
+ - next.config.js
43
+
44
+ ```js
45
+ /**
46
+ * @type { import("next").NextConfig}
47
+ */
48
+ const config = {
49
+ images: {
50
+ path: 'https://xxx.yyy.workers.dev/',
51
+ },
52
+ };
53
+ export default config;
54
+ ```
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "wasm-image-optimization",
3
3
  "description": "Optimize images with wasm on edge runtime",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/cjs/index.d.ts",
7
7
  "exports": {