@divriots/jampack 0.1.5 → 0.1.7
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 +3 -4
- 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
|
@@ -8,7 +8,6 @@ import options from './options.js';
|
|
|
8
8
|
import { compressImage } from './compress.js';
|
|
9
9
|
import svgToMiniDataURI from 'mini-svg-data-uri';
|
|
10
10
|
import globalState from './state.js';
|
|
11
|
-
import { exit } from 'process';
|
|
12
11
|
async function analyse(file) {
|
|
13
12
|
console.log('Processing ' + file);
|
|
14
13
|
const html = (await fs.readFile(path.join(globalState.dir, file))).toString();
|
|
@@ -142,7 +141,7 @@ async function processImage(file, $, imgElement) {
|
|
|
142
141
|
originalSize: originalData.length,
|
|
143
142
|
compressedSize: originalData.length
|
|
144
143
|
};
|
|
145
|
-
const newImage = await compressImage(originalData, {
|
|
144
|
+
const newImage = await compressImage(originalData, {});
|
|
146
145
|
if (newImage && newImage.length < originalData.length) {
|
|
147
146
|
if (!globalState.args.nowrite) {
|
|
148
147
|
fs.writeFile(absoluteImgPath, newImage);
|
|
@@ -191,8 +190,8 @@ async function processImage(file, $, imgElement) {
|
|
|
191
190
|
catch (e) {
|
|
192
191
|
console.error('Error while processing image');
|
|
193
192
|
console.error(e);
|
|
194
|
-
// exit here
|
|
195
|
-
exit(1);
|
|
193
|
+
// exit here
|
|
194
|
+
// exit(1);
|
|
196
195
|
}
|
|
197
196
|
}
|
|
198
197
|
function setImageSize(img, meta) {
|
package/dist/options.js
CHANGED