@travetto/image 5.0.0-rc.7 → 5.0.0-rc.9

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 CHANGED
@@ -15,7 +15,7 @@ yarn add @travetto/image
15
15
 
16
16
  This module provides functionality for image resizing, and png optimization. This is primarily meant to be used in conjunction with other modules, like the [Asset](https://github.com/travetto/travetto/tree/main/module/asset#readme "Modular library for storing and retrieving binary assets") module or the [Email Compilation Support](https://github.com/travetto/travetto/tree/main/module/email-compiler#readme "Email compiling module") module. It can also be invoked directly as needed (as it can be very handy for batch processing images on the command line).
17
17
 
18
- The utility's primary structure revolves around the [CommandOperation](https://github.com/travetto/travetto/tree/main/module/command/src/command.ts#L12) from the [Command](https://github.com/travetto/travetto/tree/main/module/command#readme "Support for executing complex commands at runtime.") module. The [CommandOperation](https://github.com/travetto/travetto/tree/main/module/command/src/command.ts#L12) allows for declaration of a local executable, and a fall-back docker container (mainly meant for development). The [ImageConverter](https://github.com/travetto/travetto/tree/main/module/image/src/convert.ts#L37) utilizes [ImageMagick](https://imagemagick.org/index.php), [pngquant](https://pngquant.org/), and [Jpegoptim](https://github.com/tjko/jpegoptim) as the backing for image resizing and png compression, respectively.
18
+ The utility's primary structure revolves around the [CommandOperation](https://github.com/travetto/travetto/tree/main/module/command/src/command.ts#L12) from the [Command](https://github.com/travetto/travetto/tree/main/module/command#readme "Support for executing complex commands at runtime.") module. The [CommandOperation](https://github.com/travetto/travetto/tree/main/module/command/src/command.ts#L12) allows for declaration of a local executable, and a fall-back docker container (mainly meant for development). The [ImageConverter](https://github.com/travetto/travetto/tree/main/module/image/src/convert.ts#L38) utilizes [ImageMagick](https://imagemagick.org/index.php), [pngquant](https://pngquant.org/), and [Jpegoptim](https://github.com/tjko/jpegoptim) as the backing for image resizing and png compression, respectively.
19
19
 
20
20
  **Code: Simple Image Resize**
21
21
  ```typescript
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/image",
3
- "version": "5.0.0-rc.7",
3
+ "version": "5.0.0-rc.9",
4
4
  "description": "Image support, resizing, and optimization",
5
5
  "keywords": [
6
6
  "images",
@@ -23,8 +23,8 @@
23
23
  "directory": "module/image"
24
24
  },
25
25
  "dependencies": {
26
- "@travetto/runtime": "^5.0.0-rc.7",
27
- "@travetto/command": "^5.0.0-rc.7"
26
+ "@travetto/runtime": "^5.0.0-rc.9",
27
+ "@travetto/command": "^5.0.0-rc.9"
28
28
  },
29
29
  "travetto": {
30
30
  "displayName": "Image"
package/src/convert.ts CHANGED
@@ -5,6 +5,7 @@ import { ChildProcess } from 'node:child_process';
5
5
  import { pipeline } from 'node:stream/promises';
6
6
 
7
7
  import { CommandOperation } from '@travetto/command';
8
+ import { castTo } from '@travetto/runtime';
8
9
 
9
10
  /**
10
11
  * Image output options
@@ -48,7 +49,7 @@ export class ImageConverter {
48
49
  * Compressor
49
50
  */
50
51
  static PNG_COMPRESSOR = new CommandOperation({
51
- containerImage: 'agregad/pngquant',
52
+ containerImage: 'agregad/pngquant:latest',
52
53
  localCheck: ['pngquant', ['-h']]
53
54
  });
54
55
 
@@ -62,16 +63,11 @@ export class ImageConverter {
62
63
 
63
64
  static async #stream<T extends ImageType>(proc: ChildProcess, input: T): Promise<T> {
64
65
  if (Buffer.isBuffer(input)) {
65
- const [_, output] = await Promise.all([
66
- pipeline(Readable.from(input), proc.stdin!),
67
- toBuffer(proc.stdout!)
68
- ]);
69
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
70
- return output as T;
66
+ Readable.from(input).pipe(proc.stdin!);
67
+ return castTo(toBuffer(proc.stdout!));
71
68
  } else {
72
69
  input.pipe(proc.stdin!); // Start the process
73
- // eslint-disable-next-line @typescript-eslint/consistent-type-assertions
74
- return proc.stdout! as T;
70
+ return castTo(proc.stdout);
75
71
  }
76
72
  }
77
73
 
@@ -90,7 +86,7 @@ export class ImageConverter {
90
86
  }
91
87
 
92
88
  /**
93
- * Optimize png using pngquant
89
+ * Optimize image
94
90
  */
95
91
  static async optimize<T extends ImageType>(format: 'png' | 'jpeg', image: T): Promise<T> {
96
92
  let proc: ChildProcess;