aptechka 0.11.6 → 0.11.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/package.json
CHANGED
|
@@ -234,6 +234,7 @@ async function inputFiles({
|
|
|
234
234
|
quality: 80,
|
|
235
235
|
scale: 1,
|
|
236
236
|
webp: false,
|
|
237
|
+
forceJPG: false,
|
|
237
238
|
destinationPath,
|
|
238
239
|
...(_d = settings == null ? void 0 : settings.image) == null ? void 0 : _d.call(settings, { destinationPath })
|
|
239
240
|
}
|
|
@@ -273,7 +274,6 @@ function getNumberSetting(value, min, max) {
|
|
|
273
274
|
async function optimizeImage(source) {
|
|
274
275
|
const { settings } = source;
|
|
275
276
|
const content = await getBuffer(source.content);
|
|
276
|
-
const ext = extname(settings.destinationPath).toLowerCase();
|
|
277
277
|
const image = sharp(content);
|
|
278
278
|
const meta = await image.metadata();
|
|
279
279
|
const width = meta.width;
|
|
@@ -281,6 +281,8 @@ async function optimizeImage(source) {
|
|
|
281
281
|
const output = [];
|
|
282
282
|
const scale = getNumberSetting(settings.scale, 0, 1);
|
|
283
283
|
const quality = getNumberSetting(settings.quality, 0, 100);
|
|
284
|
+
let destinationPath = settings.destinationPath;
|
|
285
|
+
let ext = extname(destinationPath).toLowerCase();
|
|
284
286
|
if (width && height) {
|
|
285
287
|
if (scale) {
|
|
286
288
|
image.resize(Math.floor(width * scale), Math.floor(height * scale));
|
|
@@ -292,17 +294,26 @@ async function optimizeImage(source) {
|
|
|
292
294
|
quality
|
|
293
295
|
});
|
|
294
296
|
} else if (ext === ".png") {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
297
|
+
if (settings.forceJPG) {
|
|
298
|
+
const bg = typeof settings.forceJPG === "string" ? settings.forceJPG : "#ffffff";
|
|
299
|
+
image.jpeg({
|
|
300
|
+
mozjpeg: true
|
|
301
|
+
}).flatten({ background: bg });
|
|
302
|
+
destinationPath = replaceExtension(settings.destinationPath, "jpg");
|
|
303
|
+
ext = ".jpg";
|
|
304
|
+
} else {
|
|
305
|
+
image.png({
|
|
306
|
+
compressionLevel: 9,
|
|
307
|
+
adaptiveFiltering: true,
|
|
308
|
+
quality,
|
|
309
|
+
effort: 8
|
|
310
|
+
});
|
|
311
|
+
}
|
|
301
312
|
}
|
|
302
313
|
const buffer = await image.toBuffer();
|
|
303
314
|
output.push({
|
|
304
315
|
data: buffer,
|
|
305
|
-
destinationPath
|
|
316
|
+
destinationPath
|
|
306
317
|
});
|
|
307
318
|
if (settings == null ? void 0 : settings.webp) {
|
|
308
319
|
const buffer2 = await image.webp({
|
|
@@ -311,17 +322,14 @@ async function optimizeImage(source) {
|
|
|
311
322
|
}).toBuffer();
|
|
312
323
|
output.push({
|
|
313
324
|
data: buffer2,
|
|
314
|
-
destinationPath: replaceExtension(
|
|
325
|
+
destinationPath: replaceExtension(destinationPath, "webp")
|
|
315
326
|
});
|
|
316
327
|
}
|
|
317
328
|
if (settings == null ? void 0 : settings.placeholder) {
|
|
318
329
|
const buffer2 = await image.resize(20, 20).blur(10).toBuffer();
|
|
319
330
|
output.push({
|
|
320
331
|
data: buffer2,
|
|
321
|
-
destinationPath: replaceExtension(
|
|
322
|
-
settings.destinationPath,
|
|
323
|
-
`placeholder${ext}`
|
|
324
|
-
)
|
|
332
|
+
destinationPath: replaceExtension(destinationPath, `placeholder${ext}`)
|
|
325
333
|
});
|
|
326
334
|
}
|
|
327
335
|
return output;
|