@uxf/resizer 2.3.1 → 2.3.3
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/.gitlab-ci.yml +2 -2
- package/README.md +12 -12
- package/index.js +29 -1
- package/package.json +1 -1
package/.gitlab-ci.yml
CHANGED
|
@@ -3,7 +3,7 @@ stages:
|
|
|
3
3
|
- release
|
|
4
4
|
|
|
5
5
|
test:
|
|
6
|
-
image: node:
|
|
6
|
+
image: node:18-buster-slim
|
|
7
7
|
stage: test
|
|
8
8
|
tags:
|
|
9
9
|
- pluto-docker
|
|
@@ -15,7 +15,7 @@ test:
|
|
|
15
15
|
- beta
|
|
16
16
|
|
|
17
17
|
release:
|
|
18
|
-
image: node:
|
|
18
|
+
image: node:18-buster-slim
|
|
19
19
|
stage: release
|
|
20
20
|
tags:
|
|
21
21
|
- pluto-docker
|
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ You can use configuration file `.resizer-config.json` or environment variable `U
|
|
|
21
21
|
```json
|
|
22
22
|
[
|
|
23
23
|
{
|
|
24
|
-
"route": "/generated/:namespace/:p1/:p2/:filename([a-f0-9\\-]+)_:width(\\d+)_:height(\\d+)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)_:quality(\\d
|
|
24
|
+
"route": "/generated/:namespace/:p1/:p2/:filename([a-f0-9\\-]+)_:width(\\d+)_:height(\\d+)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)_:quality(\\d+|x)_:extension.:toFormat",
|
|
25
25
|
"source": "/var/www/UXF/projects/resizer/example-upload/:namespace/:p1/:p2/:filename.:extension"
|
|
26
26
|
},
|
|
27
27
|
{
|
|
@@ -43,23 +43,23 @@ You can use configuration file `.resizer-config.json` or environment variable `U
|
|
|
43
43
|
"source": "https://uxf-base.uxf.dev/:filename+.:extension"
|
|
44
44
|
},
|
|
45
45
|
{
|
|
46
|
-
"route": "/generated/:namespace/:p1/:p2/:filename([a-f0-9\\-]+)_:width(\\d+|x)_:height(\\d+|x)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)_:quality(\\d
|
|
46
|
+
"route": "/generated/:namespace/:p1/:p2/:filename([a-f0-9\\-]+)_:width(\\d+|x)_:height(\\d+|x)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)_:quality(\\d+|x)_:extension.:toFormat",
|
|
47
47
|
"source": "https://s3.uxf.dev/${APP_NAME}-${APP_ENV}/:namespace/:p1/:p2/:filename.:extension"
|
|
48
48
|
}
|
|
49
49
|
]
|
|
50
50
|
```
|
|
51
51
|
|
|
52
52
|
### Supported route parameters
|
|
53
|
-
| Parameter name | Type
|
|
54
|
-
|
|
55
|
-
| width | `number` or `x` (auto)
|
|
56
|
-
| height | `number` or `x` (auto)
|
|
57
|
-
| fit | `Fit`
|
|
58
|
-
| position | `Position`
|
|
59
|
-
| background | `FFFFFF` or `t` (transparent)
|
|
60
|
-
| toFormat | `webp`, `png`, `avif`, `jpg`
|
|
61
|
-
| trim | `number` or `nt` (not trim)
|
|
62
|
-
| quality | `number` (min: 1, max: 100)
|
|
53
|
+
| Parameter name | Type | Default sharp value |
|
|
54
|
+
|----------------|------------------------------------|----------------------------------------|
|
|
55
|
+
| width | `number` or `x` (auto) | `undefined` |
|
|
56
|
+
| height | `number` or `x` (auto) | `undefined` |
|
|
57
|
+
| fit | `Fit` | cover |
|
|
58
|
+
| position | `Position` | |
|
|
59
|
+
| background | `FFFFFF` or `t` (transparent) | |
|
|
60
|
+
| toFormat | `webp`, `png`, `avif`, `jpg` | `jpg` |
|
|
61
|
+
| trim | `number` or `nt` (not trim) | |
|
|
62
|
+
| quality | `number` (min: 1, max: 100) or `x` | default of sharp (avif: 50, other: 80) |
|
|
63
63
|
|
|
64
64
|
#### Fit
|
|
65
65
|
- `cv`: cover,
|
package/index.js
CHANGED
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -46,6 +69,7 @@ var fs_1 = require("fs");
|
|
|
46
69
|
var path_1 = require("path");
|
|
47
70
|
var sharp_1 = __importDefault(require("sharp"));
|
|
48
71
|
var path_to_regexp_1 = require("path-to-regexp");
|
|
72
|
+
var fs = __importStar(require("fs"));
|
|
49
73
|
var FIT_OPTIONS = {
|
|
50
74
|
cv: "cover",
|
|
51
75
|
f: "fill",
|
|
@@ -68,7 +92,7 @@ var POSITION_OPTIONS = {
|
|
|
68
92
|
};
|
|
69
93
|
var getQuality = function (_a) {
|
|
70
94
|
var quality = _a.quality;
|
|
71
|
-
return (quality ? Number(quality) :
|
|
95
|
+
return (quality && quality !== "x" ? Number(quality) : undefined);
|
|
72
96
|
};
|
|
73
97
|
var getWidth = function (_a) {
|
|
74
98
|
var width = _a.width;
|
|
@@ -159,6 +183,10 @@ var resizerMiddleware = function (config) {
|
|
|
159
183
|
_d.label = 4;
|
|
160
184
|
case 4:
|
|
161
185
|
sourceFile = _a;
|
|
186
|
+
if (params.toFormat === "svg") {
|
|
187
|
+
fs.writeFileSync(generatedFilename, sourceFile);
|
|
188
|
+
return [2 /*return*/, res.sendFile(generatedFilename)];
|
|
189
|
+
}
|
|
162
190
|
return [4 /*yield*/, (0, sharp_1.default)(sourceFile)
|
|
163
191
|
.rotate()
|
|
164
192
|
.resize({
|