@uxf/resizer 2.2.1 → 2.3.1

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 (3) hide show
  1. package/README.md +16 -1
  2. package/index.js +10 -5
  3. package/package.json +1 -1
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]+)_:extension.:toFormat",
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+)_:extension.:toFormat",
25
25
  "source": "/var/www/UXF/projects/resizer/example-upload/:namespace/:p1/:p2/:filename.:extension"
26
26
  },
27
27
  {
@@ -35,6 +35,20 @@ You can use configuration file `.resizer-config.json` or environment variable `U
35
35
  ]
36
36
  ```
37
37
 
38
+ ### UXF Basic configuration
39
+ ```json
40
+ [
41
+ {
42
+ "route": "/generated/static/:width(\\d+|x)_:height(\\d+|x)_:fit([a-z]+)_:position([a-z]+)_:background([a-z]+)_:trim([a-z]+)/:version/:filename(*).:extension.:toFormat",
43
+ "source": "https://uxf-base.uxf.dev/:filename+.:extension"
44
+ },
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+)_:extension.:toFormat",
47
+ "source": "https://s3.uxf.dev/${APP_NAME}-${APP_ENV}/:namespace/:p1/:p2/:filename.:extension"
48
+ }
49
+ ]
50
+ ```
51
+
38
52
  ### Supported route parameters
39
53
  | Parameter name | Type | Default sharp value |
40
54
  |----------------|-------------------------------|---------------------|
@@ -45,6 +59,7 @@ You can use configuration file `.resizer-config.json` or environment variable `U
45
59
  | background | `FFFFFF` or `t` (transparent) | |
46
60
  | toFormat | `webp`, `png`, `avif`, `jpg` | `jpg` |
47
61
  | trim | `number` or `nt` (not trim) | |
62
+ | quality | `number` (min: 1, max: 100) | 60 |
48
63
 
49
64
  #### Fit
50
65
  - `cv`: cover,
package/index.js CHANGED
@@ -66,6 +66,10 @@ var POSITION_OPTIONS = {
66
66
  rt: "right top",
67
67
  t: "top",
68
68
  };
69
+ var getQuality = function (_a) {
70
+ var quality = _a.quality;
71
+ return (quality ? Number(quality) : 60);
72
+ };
69
73
  var getWidth = function (_a) {
70
74
  var width = _a.width;
71
75
  return (width && width !== "x" ? Number(width) : undefined);
@@ -122,7 +126,7 @@ var resizerMiddleware = function (config) {
122
126
  log(" Route: ".concat(c.route));
123
127
  log(" Source: ".concat(c.source));
124
128
  middleware.get(c.route, function (req, res) { return __awaiter(void 0, void 0, void 0, function () {
125
- var url, domain, repairedParams, sourceFilename, generatedFilename, generatedDirectory, params, sourceFile, _a, pipeline, trim;
129
+ var url, domain, repairedParams, sourceFilename, generatedFilename, generatedDirectory, params, sourceFile, _a, pipeline, trim, quality;
126
130
  var _b, _c;
127
131
  return __generator(this, function (_d) {
128
132
  switch (_d.label) {
@@ -172,21 +176,22 @@ var resizerMiddleware = function (config) {
172
176
  if (trim !== undefined) {
173
177
  pipeline.trim(trim);
174
178
  }
179
+ quality = getQuality(params);
175
180
  switch (params.toFormat) {
176
181
  case "webp":
177
- pipeline.webp({ quality: 60 });
182
+ pipeline.webp({ quality: quality });
178
183
  res.setHeader("Content-Type", "image/webp");
179
184
  break;
180
185
  case "png":
181
- pipeline.png({ progressive: true, quality: 60 });
186
+ pipeline.png({ progressive: true, quality: quality });
182
187
  res.setHeader("Content-Type", "image/png");
183
188
  break;
184
189
  case "avif":
185
- pipeline.avif();
190
+ pipeline.avif({ quality: quality });
186
191
  res.setHeader("Content-Type", "image/avif");
187
192
  break;
188
193
  default:
189
- pipeline.jpeg({ progressive: true, quality: 60 });
194
+ pipeline.jpeg({ progressive: true, quality: quality });
190
195
  res.setHeader("Content-Type", "image/jpeg");
191
196
  break;
192
197
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/resizer",
3
- "version": "2.2.1",
3
+ "version": "2.3.1",
4
4
  "main": "index.js",
5
5
  "description": "UXF Resizer",
6
6
  "author": "UXFans <dev@uxf.cz>",