maverick-wave-astro 1.44.0 → 1.45.0
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/dist/image-size.js +30 -0
- package/package.json +1 -1
package/dist/image-size.js
CHANGED
|
@@ -31,6 +31,34 @@ const readJpeg = (buffer) => {
|
|
|
31
31
|
}
|
|
32
32
|
return null;
|
|
33
33
|
};
|
|
34
|
+
const readWebp = (buffer) => {
|
|
35
|
+
if (buffer.length < 30 ||
|
|
36
|
+
buffer.toString('latin1', 0, 4) !== 'RIFF' ||
|
|
37
|
+
buffer.toString('latin1', 8, 12) !== 'WEBP')
|
|
38
|
+
return null;
|
|
39
|
+
// VP8X and VP8L store the size minus one, VP8 keeps scale bits above 14.
|
|
40
|
+
switch (buffer.toString('latin1', 12, 16)) {
|
|
41
|
+
case 'VP8X':
|
|
42
|
+
return {
|
|
43
|
+
width: buffer.readUIntLE(24, 3) + 1,
|
|
44
|
+
height: buffer.readUIntLE(27, 3) + 1,
|
|
45
|
+
};
|
|
46
|
+
case 'VP8 ':
|
|
47
|
+
return {
|
|
48
|
+
width: buffer.readUInt16LE(26) & 0x3fff,
|
|
49
|
+
height: buffer.readUInt16LE(28) & 0x3fff,
|
|
50
|
+
};
|
|
51
|
+
case 'VP8L': {
|
|
52
|
+
const bits = buffer.readUInt32LE(21);
|
|
53
|
+
return {
|
|
54
|
+
width: (bits & 0x3fff) + 1,
|
|
55
|
+
height: ((bits >> 14) & 0x3fff) + 1,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
default:
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
34
62
|
const readSvg = (buffer) => {
|
|
35
63
|
const head = buffer.subarray(0, 2048).toString('utf-8');
|
|
36
64
|
const viewBox = head.match(/viewBox=["']\s*[\d.-]+\s+[\d.-]+\s+([\d.]+)\s+([\d.]+)/);
|
|
@@ -52,6 +80,8 @@ export const imageSize = (publicPath) => {
|
|
|
52
80
|
size = readSvg(buffer);
|
|
53
81
|
else if (/\.jpe?g$/.test(publicPath))
|
|
54
82
|
size = readJpeg(buffer);
|
|
83
|
+
else if (publicPath.endsWith('.webp'))
|
|
84
|
+
size = readWebp(buffer);
|
|
55
85
|
else
|
|
56
86
|
size = readPng(buffer);
|
|
57
87
|
}
|
package/package.json
CHANGED