@travetto/image 5.0.3 → 5.0.5

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/package.json +3 -3
  2. package/src/util.ts +7 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/image",
3
- "version": "5.0.3",
3
+ "version": "5.0.5",
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/command": "^5.0.3",
27
- "@travetto/runtime": "^5.0.3",
26
+ "@travetto/command": "^5.0.4",
27
+ "@travetto/runtime": "^5.0.4",
28
28
  "sharp": "^0.33.5"
29
29
  },
30
30
  "travetto": {
package/src/util.ts CHANGED
@@ -25,10 +25,6 @@ export interface ResizeOptions {
25
25
  * Should the image be optimized?
26
26
  */
27
27
  optimize?: boolean;
28
- /**
29
- * Strict resolution
30
- */
31
- strictResolution?: boolean;
32
28
  /**
33
29
  * Sub process, allows for externalization of memory
34
30
  */
@@ -106,10 +102,12 @@ export class ImageUtil {
106
102
  * Resize image
107
103
  */
108
104
  static async resize<T extends ImageType>(image: T, options: ResizeOptions = {}): Promise<T> {
109
- const dims = [options.w, options.h].map(d => (!d && options.strictResolution === false) ? undefined : d);
105
+ const dims = [options.w, options.h].map(x => x ? Math.trunc(x) : undefined);
106
+ const fluid = dims.some(x => !x);
107
+
110
108
  if (options.asSubprocess) {
111
109
  return this.#subprocessReturn(
112
- await this.CONVERTER.exec('gm', 'convert', '-resize', dims.join('x'), '-auto-orient',
110
+ await this.CONVERTER.exec('gm', 'convert', '-resize', dims.map(x => x || '').join('x'), '-auto-orient',
113
111
  ...(options.optimize ? ['-strip', '-quality', '86'] : []), '-', '-'),
114
112
  image);
115
113
  } else {
@@ -119,7 +117,7 @@ export class ImageUtil {
119
117
  sharp().resize({
120
118
  width: dims[0],
121
119
  height: dims[1],
122
- fit: options.strictResolution !== false ? 'fill' : 'inside'
120
+ fit: fluid ? 'inside' : 'fill'
123
121
  }),
124
122
  image,
125
123
  options.optimize,
@@ -148,8 +146,8 @@ export class ImageUtil {
148
146
  /**
149
147
  * Get Image Dimensions
150
148
  */
151
- static async getDimensions(image: Buffer | string): Promise<{ width: number, height: number }> {
149
+ static async getDimensions(image: Buffer | string): Promise<{ width: number, height: number, aspect: number }> {
152
150
  const { default: sharp } = await import('sharp');
153
- return sharp(image).metadata().then(v => ({ width: v.width!, height: v.height! }));
151
+ return sharp(image).metadata().then(v => ({ width: v.width!, height: v.height!, aspect: v.width! / v.height! }));
154
152
  }
155
153
  }