@divriots/jampack 0.1.6 → 0.1.8
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/compress.js +17 -2
- package/dist/optimize.js +19 -11
- package/dist/options.js +1 -1
- package/package.json +1 -1
package/dist/compress.js
CHANGED
|
@@ -89,7 +89,18 @@ export const compressImage = async (data, resize) => {
|
|
|
89
89
|
const meta = await sharpFile.metadata();
|
|
90
90
|
switch (meta.format) {
|
|
91
91
|
case 'svg':
|
|
92
|
-
const newData = svgo(data, {
|
|
92
|
+
const newData = svgo(data, {
|
|
93
|
+
multipass: true,
|
|
94
|
+
plugins: [{
|
|
95
|
+
name: "preset-default",
|
|
96
|
+
params: {
|
|
97
|
+
overrides: {
|
|
98
|
+
removeViewBox: false,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
}
|
|
102
|
+
],
|
|
103
|
+
});
|
|
93
104
|
if (newData.error || newData.modernError) {
|
|
94
105
|
console.log(`Error processing svg ${data}`);
|
|
95
106
|
return undefined;
|
|
@@ -100,7 +111,11 @@ export const compressImage = async (data, resize) => {
|
|
|
100
111
|
case 'jpeg':
|
|
101
112
|
case 'webp':
|
|
102
113
|
//case 'gif':
|
|
103
|
-
|
|
114
|
+
let sf = sharpFile;
|
|
115
|
+
if (resize.width && resize.height) {
|
|
116
|
+
sf = sf.resize({ ...resize, fit: 'fill', withoutEnlargement: true });
|
|
117
|
+
}
|
|
118
|
+
return await sf.toBuffer();
|
|
104
119
|
}
|
|
105
120
|
return undefined;
|
|
106
121
|
};
|
package/dist/optimize.js
CHANGED
|
@@ -124,14 +124,6 @@ async function processImage(file, $, imgElement) {
|
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
126
|
/*
|
|
127
|
-
* Attribute 'width' & 'height'
|
|
128
|
-
*/
|
|
129
|
-
const [w, h] = setImageSize(img, meta);
|
|
130
|
-
if (w < 0 || h < 0) {
|
|
131
|
-
console.warn(`Unexpected error in image size calculation - some optimizations can't be done`);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
/*
|
|
135
127
|
* Compress image
|
|
136
128
|
*/
|
|
137
129
|
if (!globalState.compressedFiles.has(absoluteImgPath)) {
|
|
@@ -141,7 +133,7 @@ async function processImage(file, $, imgElement) {
|
|
|
141
133
|
originalSize: originalData.length,
|
|
142
134
|
compressedSize: originalData.length
|
|
143
135
|
};
|
|
144
|
-
const newImage = await compressImage(originalData, {
|
|
136
|
+
const newImage = await compressImage(originalData, {});
|
|
145
137
|
if (newImage && newImage.length < originalData.length) {
|
|
146
138
|
if (!globalState.args.nowrite) {
|
|
147
139
|
fs.writeFile(absoluteImgPath, newImage);
|
|
@@ -150,11 +142,27 @@ async function processImage(file, $, imgElement) {
|
|
|
150
142
|
}
|
|
151
143
|
globalState.addFile(result);
|
|
152
144
|
}
|
|
145
|
+
//
|
|
146
|
+
// Stop here if svg
|
|
147
|
+
//
|
|
148
|
+
if (meta.format === 'svg')
|
|
149
|
+
return;
|
|
150
|
+
/*
|
|
151
|
+
* Attribute 'width' & 'height'
|
|
152
|
+
*/
|
|
153
|
+
const [w, h] = setImageSize(img, meta);
|
|
154
|
+
if (w < 0 || h < 0) {
|
|
155
|
+
console.warn(`Unexpected error in image size calculation - some optimizations can't be done`);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
/*
|
|
159
|
+
* Attribute 'srcset'
|
|
160
|
+
*/
|
|
153
161
|
const attr_srcset = img.attr('srcset');
|
|
154
162
|
if (attr_srcset) {
|
|
155
163
|
// If srcset is set, don't touch it.
|
|
156
|
-
//
|
|
157
|
-
//
|
|
164
|
+
// The compress pass will compress the images
|
|
165
|
+
// of the srcset
|
|
158
166
|
}
|
|
159
167
|
else {
|
|
160
168
|
// Generate image set
|
package/dist/options.js
CHANGED