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 CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "optimo",
3
3
  "description": "The no-brainer ImageMagick CLI for optimizing images",
4
4
  "homepage": "https://github.com/kikobeats/optimo",
5
- "version": "0.0.13",
5
+ "version": "0.0.15",
6
6
  "exports": {
7
7
  ".": "./src/index.js"
8
8
  },
package/src/index.js CHANGED
@@ -27,11 +27,11 @@ const runMagick = async ({
27
27
  filePath,
28
28
  optimizedPath,
29
29
  flags,
30
- resizePercentage = null
30
+ resizeGeometry = null
31
31
  }) => {
32
32
  const magickArgs = [
33
33
  filePath,
34
- ...(resizePercentage ? ['-resize', resizePercentage] : []),
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 resizePercentage = scale === 100 ? null : `${scale}%`
53
+ const resizeGeometry = scale === 100 ? null : `${scale}%`
54
54
  const size = await runMagick({
55
55
  filePath,
56
56
  optimizedPath,
57
57
  flags,
58
- resizePercentage
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
- resizePercentage: resizeConfig?.value
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 = normalized.match(/^([wh])(\d+)$/)
38
+ const dimensionMatch =
39
+ normalized.match(/^([wh])(\d+)$/) || normalized.match(/^(\d+)([wh])$/)
39
40
  if (dimensionMatch) {
40
- const axis = dimensionMatch[1]
41
- const value = Number(dimensionMatch[2])
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