ipx 1.1.0 → 1.3.0
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.
- package/README.md +107 -49
- package/bin/ipx.mjs +1 -1
- package/dist/cli.cjs +6 -5
- package/dist/cli.d.cts +2 -0
- package/dist/cli.d.mts +2 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.mjs +3 -2
- package/dist/index.cjs +681 -18
- package/dist/index.d.cts +144 -0
- package/dist/index.d.mts +144 -0
- package/dist/index.d.ts +101 -11
- package/dist/index.mjs +671 -12
- package/package.json +28 -22
- package/dist/shared/ipx.cc3515c9.mjs +0 -616
- package/dist/shared/ipx.e9f7a9b5.cjs +0 -628
package/README.md
CHANGED
|
@@ -1,83 +1,113 @@
|
|
|
1
|
-
# IPX
|
|
1
|
+
# 🖼️ IPX
|
|
2
2
|
|
|
3
|
-
[](https://packagephobia.now.sh/result?p=ipx)
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
6
5
|
|
|
7
6
|
High performance, secure and easy to use image proxy based on [sharp](https://github.com/lovell/sharp) and [libvips](https://github.com/libvips/libvips).
|
|
8
7
|
|
|
9
|
-
##
|
|
10
|
-
|
|
11
|
-
### Quick Start
|
|
8
|
+
## Using CLI
|
|
12
9
|
|
|
13
10
|
You can use `ipx` command to start server using:
|
|
14
11
|
|
|
15
12
|
```bash
|
|
16
|
-
|
|
13
|
+
npx ipx@latest
|
|
17
14
|
```
|
|
18
15
|
|
|
19
16
|
The default server directory is the current working directory.
|
|
20
17
|
|
|
21
|
-
|
|
18
|
+
## Programatic API
|
|
19
|
+
|
|
20
|
+
You can use IPX as a middleware or directly use IPX interface.
|
|
21
|
+
|
|
22
|
+
```ts
|
|
23
|
+
import { createIPX, createIPXMiddleware } from "ipx";
|
|
24
|
+
|
|
25
|
+
const ipx = createIPX({ domains: ["unjs.io"] });
|
|
26
|
+
|
|
27
|
+
// (req, res) => void
|
|
28
|
+
const ipxMiddleware = createIPXMiddleware(ipx);
|
|
29
|
+
```
|
|
22
30
|
|
|
23
|
-
|
|
31
|
+
**Example**: Using with [unjs/h3](https://github.com/unjs/h3):
|
|
24
32
|
|
|
25
33
|
```js
|
|
26
34
|
import { createIPX, createIPXMiddleware } from "ipx";
|
|
35
|
+
import { listen } from "listhen";
|
|
36
|
+
import { createApp, fromNodeMiddleware, toNodeListener } from "h3";
|
|
37
|
+
|
|
38
|
+
const ipx = createIPX({});
|
|
39
|
+
const ipxMiddleware = createIPXMiddleware(ipx);
|
|
40
|
+
|
|
41
|
+
const app = createApp().use("/", fromNodeMiddleware(ipxMiddleware));
|
|
27
42
|
|
|
28
|
-
|
|
29
|
-
const app = express();
|
|
30
|
-
app.use("/image", createIPXMiddleware(ipx));
|
|
43
|
+
listen(toNodeListener(app));
|
|
31
44
|
```
|
|
32
45
|
|
|
33
|
-
|
|
46
|
+
**Example:** Using [express](https://expressjs.com):
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import { createIPX, createIPXMiddleware } from "ipx";
|
|
50
|
+
import { listen } from "listhen";
|
|
51
|
+
import express from "express";
|
|
34
52
|
|
|
35
|
-
|
|
53
|
+
const ipx = createIPX({});
|
|
54
|
+
const ipxMiddleware = createIPXMiddleware(ipx);
|
|
55
|
+
|
|
56
|
+
const app = express().use("/", ipxMiddleware);
|
|
57
|
+
|
|
58
|
+
listen(app);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Examples
|
|
36
62
|
|
|
37
63
|
Get original image:
|
|
38
64
|
|
|
39
|
-
|
|
65
|
+
`/_/static/buffalo.png`
|
|
40
66
|
|
|
41
67
|
Change format to `webp` and keep other things same as source:
|
|
42
68
|
|
|
43
|
-
|
|
69
|
+
`/f_webp/static/buffalo.png`
|
|
44
70
|
|
|
45
71
|
Keep original format (`png`) and set width to `200`:
|
|
46
72
|
|
|
47
|
-
|
|
73
|
+
`/w_200/static/buffalo.png`
|
|
48
74
|
|
|
49
75
|
Resize to `200x200px` using `embed` method and change format to `webp`:
|
|
50
76
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
| Property
|
|
56
|
-
|
|
|
57
|
-
| width / w
|
|
58
|
-
| height / h
|
|
59
|
-
| resize / s
|
|
60
|
-
|
|
|
61
|
-
|
|
|
62
|
-
|
|
|
63
|
-
|
|
|
64
|
-
|
|
|
65
|
-
|
|
|
66
|
-
|
|
|
67
|
-
|
|
|
68
|
-
|
|
|
69
|
-
|
|
|
70
|
-
|
|
|
71
|
-
|
|
|
72
|
-
|
|
|
73
|
-
|
|
|
74
|
-
|
|
|
75
|
-
|
|
|
76
|
-
|
|
|
77
|
-
|
|
|
78
|
-
|
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
`/embed,f_webp,s_200x200/static/buffalo.png`
|
|
78
|
+
|
|
79
|
+
## Modifiers
|
|
80
|
+
|
|
81
|
+
| Property | Docs | Example | Comments |
|
|
82
|
+
| -------------- | :-------------------------------------------------------------- | :--------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
83
|
+
| width / w | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/width_200/buffalo.png` |
|
|
84
|
+
| height / h | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/height_200/buffalo.png` |
|
|
85
|
+
| resize / s | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200/buffalo.png` |
|
|
86
|
+
| kernel | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200,kernel_nearest/buffalo.png` | Supported kernel: `nearest`, `cubic`, `mitchell`, `lanczos2` and `lanczos3` (default). |
|
|
87
|
+
| fit | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200,fit_outside/buffalo.png` | Sets `fit` option for `resize`. |
|
|
88
|
+
| position / pos | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200,pos_top/buffalo.png` | Sets `position` option for `resize`. |
|
|
89
|
+
| trim | [Docs](https://sharp.pixelplumbing.com/api-resize#trim) | `/trim_100/buffalo.png` |
|
|
90
|
+
| extend | [Docs](https://sharp.pixelplumbing.com/api-resize#extend) | `/extend_{top}_{right}_{bottom}_{left}/buffalo.png` | Extend / pad / extrude one or more edges of the image with either the provided background colour or pixels derived from the image. |
|
|
91
|
+
| background / b | \_ | `/r_45,b_00ff00/buffalo.png` |
|
|
92
|
+
| extract | [Docs](https://sharp.pixelplumbing.com/api-resize#extract) | `/extract_{left}_{top}_{width}_{height}/buffalo.png` | Extract/crop a region of the image. |
|
|
93
|
+
| format / f | [Docs](https://sharp.pixelplumbing.com/api-output#toformat) | `/format_webp/buffalo.png` | Supported format: `jpg`, `jpeg`, `png`, `webp`, `avif`, `gif`, `heif`, `tiff` and `auto` (experimental only with middleware) |
|
|
94
|
+
| quality / q | \_ | `/quality_50/buffalo.png` | Accepted values: 0 to 100 |
|
|
95
|
+
| rotate | [Docs](https://sharp.pixelplumbing.com/api-operation#rotate) | `/rotate_45/buffalo.png` |
|
|
96
|
+
| enlarge | \_ | `/enlarge,s_2000x2000/buffalo.png` | Allow the image to be upscaled. By default the returned image will never be larger than the source in any dimension, while preserving the requested aspect ratio. |
|
|
97
|
+
| flip | [Docs](https://sharp.pixelplumbing.com/api-operation#flip) | `/flip/buffalo.png` |
|
|
98
|
+
| flop | [Docs](https://sharp.pixelplumbing.com/api-operation#flop) | `/flop/buffalo.png` |
|
|
99
|
+
| sharpen | [Docs](https://sharp.pixelplumbing.com/api-operation#sharpen) | `/sharpen_30/buffalo.png` |
|
|
100
|
+
| median | [Docs](https://sharp.pixelplumbing.com/api-operation#median) | `/median_10/buffalo.png` |
|
|
101
|
+
| blur | [Docs](https://sharp.pixelplumbing.com/api-operation#blur) | `/blur_5/buffalo.png` |
|
|
102
|
+
| gamma | [Docs](https://sharp.pixelplumbing.com/api-operation#gamma) | `/gamma_3/buffalo.png` |
|
|
103
|
+
| negate | [Docs](https://sharp.pixelplumbing.com/api-operation#negate) | `/negate/buffalo.png` |
|
|
104
|
+
| normalize | [Docs](https://sharp.pixelplumbing.com/api-operation#normalize) | `/normalize/buffalo.png` |
|
|
105
|
+
| threshold | [Docs](https://sharp.pixelplumbing.com/api-operation#threshold) | `/threshold_10/buffalo.png` |
|
|
106
|
+
| tint | [Docs](https://sharp.pixelplumbing.com/api-colour#tint) | `/tint_1098123/buffalo.png` |
|
|
107
|
+
| grayscale | [Docs](https://sharp.pixelplumbing.com/api-colour#grayscale) | `/grayscale/buffalo.png` |
|
|
108
|
+
| animated | - | `/animated/buffalo.gif` | Experimental |
|
|
109
|
+
|
|
110
|
+
## Config
|
|
81
111
|
|
|
82
112
|
Config can be customized using `IPX_*` environment variables.
|
|
83
113
|
|
|
@@ -86,8 +116,36 @@ Config can be customized using `IPX_*` environment variables.
|
|
|
86
116
|
- Default: `.` (current working directory)
|
|
87
117
|
|
|
88
118
|
- `IPX_DOMAINS`
|
|
119
|
+
|
|
89
120
|
- Default: `[]`
|
|
90
121
|
|
|
122
|
+
- `IPX_MAX_AGE`
|
|
123
|
+
|
|
124
|
+
- Default: `300`
|
|
125
|
+
|
|
126
|
+
- `IPX_ALIAS`
|
|
127
|
+
|
|
128
|
+
- Default: `{}`
|
|
129
|
+
|
|
130
|
+
- `IPX_FETCH_OPTIONS`
|
|
131
|
+
|
|
132
|
+
- Default: `{}`
|
|
133
|
+
|
|
91
134
|
## License
|
|
92
135
|
|
|
93
|
-
MIT
|
|
136
|
+
[MIT](./LICENSE)
|
|
137
|
+
|
|
138
|
+
<!-- Badges -->
|
|
139
|
+
|
|
140
|
+
[npm-version-src]: https://img.shields.io/npm/v/ipx?style=flat&colorA=18181B&colorB=F0DB4F
|
|
141
|
+
[npm-version-href]: https://npmjs.com/package/ipx
|
|
142
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/ipx?style=flat&colorA=18181B&colorB=F0DB4F
|
|
143
|
+
[npm-downloads-href]: https://npmjs.com/package/ipx
|
|
144
|
+
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/ipx/ci/main?style=flat&colorA=18181B&colorB=F0DB4F
|
|
145
|
+
[github-actions-href]: https://github.com/unjs/ipx/actions?query=workflow%3Aci
|
|
146
|
+
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/ipx/main?style=flat&colorA=18181B&colorB=F0DB4F
|
|
147
|
+
[codecov-href]: https://codecov.io/gh/unjs/ipx
|
|
148
|
+
[bundle-src]: https://img.shields.io/bundlephobia/minzip/ipx?style=flat&colorA=18181B&colorB=F0DB4F
|
|
149
|
+
[bundle-href]: https://bundlephobia.com/result?p=ipx
|
|
150
|
+
[license-src]: https://img.shields.io/github/license/unjs/ipx.svg?style=flat&colorA=18181B&colorB=F0DB4F
|
|
151
|
+
[license-href]: https://github.com/unjs/ipx/blob/main/LICENSE
|
package/bin/ipx.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import
|
|
2
|
+
import "../dist/cli.mjs";
|
package/dist/cli.cjs
CHANGED
|
@@ -2,16 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
const consola = require('consola');
|
|
4
4
|
const listhen = require('listhen');
|
|
5
|
-
const
|
|
5
|
+
const index = require('./index.cjs');
|
|
6
6
|
require('defu');
|
|
7
7
|
require('image-meta');
|
|
8
8
|
require('ufo');
|
|
9
9
|
require('node:fs');
|
|
10
10
|
require('pathe');
|
|
11
|
+
require('destr');
|
|
11
12
|
require('node:http');
|
|
12
13
|
require('node:https');
|
|
13
14
|
require('node-fetch-native');
|
|
14
|
-
require('
|
|
15
|
+
require('@fastify/accept-negotiator');
|
|
15
16
|
require('etag');
|
|
16
17
|
require('xss');
|
|
17
18
|
|
|
@@ -20,9 +21,9 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
20
21
|
const consola__default = /*#__PURE__*/_interopDefaultCompat(consola);
|
|
21
22
|
|
|
22
23
|
async function main() {
|
|
23
|
-
const ipx =
|
|
24
|
-
const middleware
|
|
25
|
-
await listhen.listen(middleware
|
|
24
|
+
const ipx = index.createIPX({});
|
|
25
|
+
const middleware = index.createIPXMiddleware(ipx);
|
|
26
|
+
await listhen.listen(middleware, {
|
|
26
27
|
clipboard: false
|
|
27
28
|
});
|
|
28
29
|
}
|
package/dist/cli.d.cts
ADDED
package/dist/cli.d.mts
ADDED
package/dist/cli.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
|
|
2
|
-
export {
|
|
2
|
+
export { }
|
package/dist/cli.mjs
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import consola from 'consola';
|
|
2
2
|
import { listen } from 'listhen';
|
|
3
|
-
import {
|
|
3
|
+
import { createIPX, createIPXMiddleware } from './index.mjs';
|
|
4
4
|
import 'defu';
|
|
5
5
|
import 'image-meta';
|
|
6
6
|
import 'ufo';
|
|
7
7
|
import 'node:fs';
|
|
8
8
|
import 'pathe';
|
|
9
|
+
import 'destr';
|
|
9
10
|
import 'node:http';
|
|
10
11
|
import 'node:https';
|
|
11
12
|
import 'node-fetch-native';
|
|
12
|
-
import '
|
|
13
|
+
import '@fastify/accept-negotiator';
|
|
13
14
|
import 'etag';
|
|
14
15
|
import 'xss';
|
|
15
16
|
|