spark-html-image 0.1.1 → 0.1.2
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 +13 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "spark-html-image",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Build-time image optimization for spark-html sites — a Vite plugin that converts <img> references to webp/avif with responsive srcset, zero config.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/index.js
CHANGED
|
@@ -121,7 +121,15 @@ export default function sparkImage(options = {}) {
|
|
|
121
121
|
let m = meta.get(file);
|
|
122
122
|
if (!m) {
|
|
123
123
|
const info = await sharp(file).metadata();
|
|
124
|
-
|
|
124
|
+
// EXIF orientations 5–8 display the image rotated 90° — the
|
|
125
|
+
// metadata reports the SENSOR dimensions, so swap to get the
|
|
126
|
+
// dimensions the page actually renders (and that the rotated
|
|
127
|
+
// variants below will have).
|
|
128
|
+
const swap = (info.orientation || 1) >= 5;
|
|
129
|
+
m = {
|
|
130
|
+
width: (swap ? info.height : info.width) || 0,
|
|
131
|
+
height: (swap ? info.width : info.height) || 0,
|
|
132
|
+
};
|
|
125
133
|
meta.set(file, m);
|
|
126
134
|
}
|
|
127
135
|
// Widths strictly below the intrinsic width, plus the intrinsic
|
|
@@ -138,7 +146,10 @@ export default function sparkImage(options = {}) {
|
|
|
138
146
|
const dest = destUrl.startsWith('/')
|
|
139
147
|
? join(root, destUrl.slice(1))
|
|
140
148
|
: join(dirname(file), posix.basename(destUrl));
|
|
141
|
-
|
|
149
|
+
// .rotate() with no args bakes the EXIF orientation into the
|
|
150
|
+
// pixels — webp/avif output drops the EXIF tag, so without
|
|
151
|
+
// this every phone photo would render sideways.
|
|
152
|
+
let img = sharp(file).rotate();
|
|
142
153
|
if (w) img = img.resize({ width: w });
|
|
143
154
|
await img[format]({ quality }).toFile(dest);
|
|
144
155
|
converted.set(key, url);
|