@localnerve/gulp-images 0.2.0 → 0.3.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@localnerve/gulp-images",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Reusable gulp image processing transforms: optimize (svg, jpeg, png), responsive, and transform (toWebp).",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -31,10 +31,13 @@ export function jpeg (settings) {
31
31
  if (checkSkip(file, ['.jpg', '.jpeg'])) { return next(null, file); }
32
32
  if (file.isBuffer()) {
33
33
  try {
34
+ const originalLen = file.contents.length;
34
35
  const imageData = await decodeJpeg(file.contents);
35
36
  file.contents = Buffer.from(await encodeJpeg(imageData, mozjpegOptions));
37
+ const optimizedLen = file.contents.length;
38
+ const reductionPerc = (((originalLen - optimizedLen) / originalLen) * 100).toFixed(2);
36
39
 
37
- log(pluginName, file, `${file.extname.slice(1)} optimized`);
40
+ log(pluginName, file, `${file.extname.slice(1)} optimized (${reductionPerc}%)`);
38
41
  next(null, file);
39
42
  } catch (error) {
40
43
  handleError(pluginName, file, next, error);
@@ -31,10 +31,13 @@ export function png (settings) {
31
31
  if (checkSkip(file, ['.png'])) { return next(null, file); }
32
32
  if (file.isBuffer()) {
33
33
  try {
34
+ const originalLen = file.contents.length;
34
35
  const imageData = await decodePng(file.contents);
35
36
  file.contents = Buffer.from(await encodePng(imageData, oxipngOptions));
37
+ const optimizedLen = file.contents.length;
38
+ const reductionPerc = (((originalLen - optimizedLen) / originalLen) * 100).toFixed(2);
36
39
 
37
- log(pluginName, file, `${file.extname.slice(1)} optimized`);
40
+ log(pluginName, file, `${file.extname.slice(1)} optimized (${reductionPerc}%)`);
38
41
  next(null, file);
39
42
  } catch (error) {
40
43
  handleError(pluginName, file, next, error);
@@ -29,13 +29,16 @@ export function svg (settings) {
29
29
  if (checkSkip(file, ['.svg'])) { return next(null, file); }
30
30
  if (file.isBuffer()) {
31
31
  try {
32
+ const originalLen = file.contents.length;
32
33
  const result = await svgOptimize(file.contents.toString('utf8'), {
33
34
  ...svgoOptions,
34
35
  path: file.path
35
36
  });
36
37
  file.contents = Buffer.from(result.data);
38
+ const optimizedLen = file.contents.length;
39
+ const reductionPerc = (((originalLen - optimizedLen) / originalLen) * 100).toFixed(2);
37
40
 
38
- log(pluginName, file, 'svg optimized');
41
+ log(pluginName, file, `svg optimized (${reductionPerc}%)`);
39
42
  next(null, file);
40
43
  } catch (error) {
41
44
  handleError(pluginName, file, next, error);