optimo 0.0.13 → 0.0.15
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 +1 -1
- package/src/index.js +6 -5
- package/src/util.js +7 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -27,11 +27,11 @@ const runMagick = async ({
|
|
|
27
27
|
filePath,
|
|
28
28
|
optimizedPath,
|
|
29
29
|
flags,
|
|
30
|
-
|
|
30
|
+
resizeGeometry = null
|
|
31
31
|
}) => {
|
|
32
32
|
const magickArgs = [
|
|
33
33
|
filePath,
|
|
34
|
-
...(
|
|
34
|
+
...(resizeGeometry ? ['-resize', resizeGeometry] : []),
|
|
35
35
|
...flags,
|
|
36
36
|
optimizedPath
|
|
37
37
|
]
|
|
@@ -50,12 +50,12 @@ const optimizeForMaxSize = async ({
|
|
|
50
50
|
|
|
51
51
|
const measureScale = async scale => {
|
|
52
52
|
if (resultByScale.has(scale)) return resultByScale.get(scale)
|
|
53
|
-
const
|
|
53
|
+
const resizeGeometry = scale === 100 ? null : `${scale}%`
|
|
54
54
|
const size = await runMagick({
|
|
55
55
|
filePath,
|
|
56
56
|
optimizedPath,
|
|
57
57
|
flags,
|
|
58
|
-
|
|
58
|
+
resizeGeometry
|
|
59
59
|
})
|
|
60
60
|
resultByScale.set(scale, size)
|
|
61
61
|
return size
|
|
@@ -87,6 +87,7 @@ const optimizeForMaxSize = async ({
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
await measureScale(bestScale)
|
|
90
91
|
return resultByScale.get(bestScale)
|
|
91
92
|
}
|
|
92
93
|
|
|
@@ -122,7 +123,7 @@ const file = async (
|
|
|
122
123
|
filePath,
|
|
123
124
|
optimizedPath,
|
|
124
125
|
flags,
|
|
125
|
-
|
|
126
|
+
resizeGeometry: resizeConfig?.value
|
|
126
127
|
})
|
|
127
128
|
}
|
|
128
129
|
} catch {
|
package/src/util.js
CHANGED
|
@@ -35,14 +35,16 @@ const parseResize = resize => {
|
|
|
35
35
|
const raw = String(resize).trim()
|
|
36
36
|
const normalized = raw.toLowerCase().replace(/\s+/g, '')
|
|
37
37
|
|
|
38
|
-
const dimensionMatch =
|
|
38
|
+
const dimensionMatch =
|
|
39
|
+
normalized.match(/^([wh])(\d+)$/) || normalized.match(/^(\d+)([wh])$/)
|
|
39
40
|
if (dimensionMatch) {
|
|
40
|
-
const
|
|
41
|
-
const
|
|
41
|
+
const [, first, second] = dimensionMatch
|
|
42
|
+
const axis = first === 'w' || first === 'h' ? first : second
|
|
43
|
+
const value = Number(first === axis ? second : first)
|
|
42
44
|
|
|
43
45
|
if (!Number.isFinite(value) || value <= 0) {
|
|
44
46
|
throw new TypeError(
|
|
45
|
-
'Resize width/height must be greater than 0 (e.g. w960, h480)'
|
|
47
|
+
'Resize width/height must be greater than 0 (e.g. w960, 960w, h480, 480h)'
|
|
46
48
|
)
|
|
47
49
|
}
|
|
48
50
|
|
|
@@ -73,7 +75,7 @@ const parseResize = resize => {
|
|
|
73
75
|
|
|
74
76
|
if (!Number.isFinite(value) || value <= 0) {
|
|
75
77
|
throw new TypeError(
|
|
76
|
-
'Resize must be a percentage (50%), max size (100kB), width (w960), or height (h480)'
|
|
78
|
+
'Resize must be a percentage (50%), max size (100kB), width (w960/960w), or height (h480/480h)'
|
|
77
79
|
)
|
|
78
80
|
}
|
|
79
81
|
|