@travetto/image 7.0.0-rc.1 → 7.0.0-rc.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/package.json +2 -2
- package/src/util.ts +5 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/image",
|
|
3
|
-
"version": "7.0.0-rc.
|
|
3
|
+
"version": "7.0.0-rc.3",
|
|
4
4
|
"description": "Image support, resizing, and optimization",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"images",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"directory": "module/image"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@travetto/runtime": "^7.0.0-rc.
|
|
26
|
+
"@travetto/runtime": "^7.0.0-rc.3",
|
|
27
27
|
"sharp": "^0.34.5"
|
|
28
28
|
},
|
|
29
29
|
"travetto": {
|
package/src/util.ts
CHANGED
|
@@ -39,13 +39,13 @@ export class ImageUtil {
|
|
|
39
39
|
/**
|
|
40
40
|
* Convert image
|
|
41
41
|
*/
|
|
42
|
-
static async convert<T extends Input>(image: T, { format, optimize, ...
|
|
42
|
+
static async convert<T extends Input>(image: T, { format, optimize, ...options }: ConvertOptions): Promise<T extends string ? Readable : T> {
|
|
43
43
|
const { default: sharp } = await import('sharp');
|
|
44
44
|
|
|
45
45
|
let builder = sharp();
|
|
46
|
-
if (
|
|
47
|
-
const dims = [
|
|
48
|
-
const fluid = dims.some(
|
|
46
|
+
if (options.w || options.h) {
|
|
47
|
+
const dims = [options.w, options.h].map(value => value ? Math.trunc(value) : undefined);
|
|
48
|
+
const fluid = dims.some(value => !value);
|
|
49
49
|
builder = builder.resize({
|
|
50
50
|
width: dims[0],
|
|
51
51
|
height: dims[1],
|
|
@@ -88,7 +88,7 @@ export class ImageUtil {
|
|
|
88
88
|
const out = await ((Buffer.isBuffer(image) || typeof image === 'string') ?
|
|
89
89
|
sharp(image).metadata() :
|
|
90
90
|
new Promise<Metadata>((resolve, reject) =>
|
|
91
|
-
pipeline(image, sharp().metadata((
|
|
91
|
+
pipeline(image, sharp().metadata((error, metadata) => error ? reject(error) : resolve(metadata)))
|
|
92
92
|
));
|
|
93
93
|
return {
|
|
94
94
|
width: out.width!,
|