GithubHelp home page GithubHelp logo

yuriy-svetlov / compress-images Goto Github PK

View Code? Open in Web Editor NEW
588.0 10.0 77.0 17.96 MB

Minify size your images. Image compression with extension: jpg/jpeg, svg, png, gif. NodeJs

Home Page: https://www.npmjs.com/package/compress-images

License: MIT License

JavaScript 22.31% Batchfile 0.05% C 77.64%
compress-images jpeg minify gif pngout image-compression compression pngquant png png-optimizer

compress-images's People

Contributors

connum avatar idd-soliveira avatar kdlcruz avatar lpmi-13 avatar proicons avatar saionaro avatar sergiomatheus avatar yuriy-svetlov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

compress-images's Issues

Exclude folder

Hi!!

How can I compress all images except those in a folder?
I would like to compress all the images inside the 'images' folder and then compress all the svg's inside the 'icons' folder.

image

compress-images.js

/**
 * @constant compressImages
 * @type NPM Package
 * @requires compress-images npm run compress-images --save-dev
 * @see {@link https://www.npmjs.com/package/compress-images}
 */
const { compress } = require('compress-images/promise');

/**
 * @function compressImages
 * @description Minify size images compression with extension: jpg/jpeg, svg, png, gif.
 * @param {string} inputPath Path of the images to compress
 * @param {string} outputPath Path of the folder to save the images compressed
 * @requires compress-images - NPM Package compress-images/promise
 * @see {@link https://github.com/semiromid/compress-images}
 */
function compressImages(inputPath, outputPath) {
	const processImages = async(onProgress) => {
		const result = await compress({
			source: `${inputPath}*.{jpg,JPG,jpeg,JPEG,png,svg,gif}`,
			destination: outputPath,
			onProgress,
			enginesSetup: {
				jpg: {
					engine: 'mozjpeg',
					command: [
						'-quality',
						'60'
					],
				},
				png: {
					engine: 'pngquant',
					command: ['--quality=20-50'],
				},
				svg: {
					engine: 'svgo',
					command: ['--multipass'],
				},
				gif: {
					engine: 'gifsicle',
					command: [
						'--colors',
						'64',
						'--use-col=web'
					],
				},
			},
		});

		// eslint-disable-next-line no-unused-vars
		const { statistics, errors } = result;

		/*
		 * Statistics - all processed images list
		 * errors - all errors happened list
		 */
	};

	processImages((error, statistic, completed) => {
		// eslint-disable-next-line quotes
		console.info("-------------");
		if (error) {
			console.info(`Error happen while processing file: ${error}`);

			return;
		}
		if (completed) {
			console.info(`Sucefully processed file: ${completed}`);
		}
		console.info(statistic);
		console.info('-------------');
	});
}

(function() {
	compressImages('./src/images/**/', './dist/images/');
	compressImages('./src/images/icons/', './dist/images/icons/svg/');
}());

Could it be something like this?
./src/images/**!icons/

Thanks!! :)

Single image path issue

I am using this on windows and I am trying to compress an image that is uploaded by the form. I can see that the form is saving the image properly. I can also console.log the path and it is correct but I keep getting path issue. If I pass *.{jpg, ....} it works but but it will ignore the output path.

import express from 'express';
import fileUpload from 'express-fileupload';
import path from 'path';
import compress_images from 'compress-images';

const router = express.Router();
router.use(fileUpload());

router.get('/', (req, res) => res.send('Router path is loading'));

router.post('/', (req, res) => {
    console.log('request files', req.files.filepond.name);
    const file = req.files.filepond;
    const filePath = path.resolve('public/images/raw/', file.name);

    file.mv(filePath, function(err) {
        if (err) {
            console.log('error happened', err);
            return res.status(500).send(err);
        }
        compressImage(filePath);
        res.json({
            file: `${filePath}`,
        });
    });
});

function compressImage(rawImage) {
    console.log(rawImage);
    compress_images(
        rawImage,
        path.resolve('public/images/optimized'),
        { compress_force: false, statistic: true, autoupdate: true },
        false,
        { jpg: { engine: 'webp', command: ['-q', '75'] } },
        { png: { engine: false, command: false } },
        { svg: { engine: false, command: false } },
        { gif: { engine: false, command: false } },
        function(err) {
            if (err === null) {
                //[jpg] ---to---> [jpg(jpegtran)] WARNING!!! autoupdate  - recommended to turn this off, it's not needed here - autoupdate: false

                compress_images(
                    rawImage,
                    path.resolve('public/images/optimized'),
                    {
                        compress_force: false,
                        statistic: true,
                        autoupdate: false,
                    },
                    false,
                    {
                        jpg: {
                            engine: 'mozjpeg',
                            command: ['-quality', '75', '-progressive'],
                        },
                    },
                    { png: { engine: false, command: false } },
                    { svg: { engine: false, command: false } },
                    { gif: { engine: false, command: false } },
                    function(err) {
                        console.log('error on second', err);
                    }
                );
            } else {
                console.error(err);
            }
        }
    );
}

export default router;

How to deal with Base64 strings?

Hi,

I have my images as Base64 strings. How could I deal with that? Is there an API to feed them into?

greetings and thanks,
André

Error: ENOENT: no such file or directory

Really strange, it's working fine on my localhost. When moving to production I am now getting this error when trying to compress:

binding.stat(pathModule._makeLong(path), statValues);
          ^

0|app      | Error: ENOENT: no such file or directory, stat 'public/compressed/image-1517857639606.jpg'
0|app      |     at Error (native)
0|app      |     at Object.fs.statSync (fs.js:1009:11)
0|app      |     at getFilesizeInBytes (/home/bud/node_modules/compress-images/index.js:1360:23)
0|app      |     at /home/bud/node_modules/compress-images/index.js:569:29
0|app      |     at exithandler (child_process.js:206:5)
0|app      |     at ChildProcess.errorhandler (child_process.js:218:5)
0|app      |     at emitOne (events.js:96:13)
0|app      |     at ChildProcess.emit (events.js:188:7)
0|app      |     at Process.ChildProcess._handle.onexit (internal/child_process.                                                                                                                     js:217:12)
0|app      |     at onErrorNT (internal/child_process.js:376:16)
0|app      |     at _combinedTickCallback (internal/process/next_tick.js:80:11)
0|app      |     at process._tickDomainCallback (internal/process/next_tick.js:1                                                                                                                     28:9)
0|app      | (node:2103) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead, or set the `useMongoClient` option if using                                                                                                                      `connect()` or `createConnection()`. See http://mongoosejs.com/docs/connections.                                                                                                                     html#use-mongo-client

This is my setup:

// Image Compression
function rszImg(){
    compress_images('public/uploads/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}', 'public/', {compress_force: false, statistic: true, autoupdate: true}, false,
                                                {jpg: {engine: 'mozjpeg', command: ['-quality', '40']}},
                                                {png: {engine: 'pngquant', command: ['--quality=20-50']}},
                                                {svg: {engine: 'svgo', command: '--multipass'}},
                                                {gif: {engine: 'gifsicle', command: ['--colors', '64', '--use-col=web']}}, function(){
    });
}

Both my localhost and production server are running Node -v 8.9.4

Error: exists; not overwriting

Your module seems to try to write several times the same file.
All my directories are deleted everytime before running the script so it's impossible the file already exists in the destination directory.

 File from: /home/libre/Documents/Knights/pvp/8axis/sprites/spritesheets/thrust5.png
 File to: /home/libre/Documents/Knights/pvp/8axis/sprites/compressed/thrust5.png
 Compression algorithm: [pngquant]
{ Error: Command failed: /home/libre/dev/knights.io/node_modules/pngquant-bin/vendor/pngquant --quality=20-50 -o /home/libre/Documents/Knights/pvp/8axis/sprites/compressed/thrust5.png /home/libre/Documents/Knights/pvp/8axis/sprites/spritesheets/thrust5.png
  error: '/home/libre/Documents/Knights/pvp/8axis/sprites/compressed/thrust5.png' exists; not overwriting

    at ChildProcess.exithandler (child_process.js:273:12)
    at ChildProcess.emit (events.js:180:13)
    at maybeClose (internal/child_process.js:936:16)
    at Socket.stream.socket.on (internal/child_process.js:353:11)
    at Socket.emit (events.js:180:13)
    at Pipe._handle.close [as _onclose] (net.js:538:12)
  killed: false,
  code: 15,
  signal: null,
  cmd: '/home/libre/dev/knights.io/node_modules/pngquant-bin/vendor/pngquant --quality=20-50 -o /home/libre/Documents/Knights/pvp/8axis/sprites/compressed/thrust5.png /home/libre/Documents/Knights/pvp/8axis/sprites/spritesheets/thrust5.png' }

images are not saved to exact paths

Hello, your package partly works for me, but it does not save the images already compressed in the folder that I specify

If you notice, I specify the directory where the original image is located as well as the directory where the compressed image will be stored

image

and the output message confirms to me that it was successfully saved to the directory that I specified
image

but when I go to check to confirm, it was not saved in said directory, but rather it is saved where the original one is and to the name it adds a suffix "-fs8"
image
I hope you can help me

Pathing when using libray within electron application

Hi when I use this library within an electron application I have to provide a path relative to the application source, when I would like to provide an absolute path, that can use cross platform locations.

For example:

INPUT_PATH = ${os.homedir()}/MyAppSpecificPath/**/*.{png,jpg,svg}``

returns a Directory is empty! error from Line 243 index.js

INPUT_PATH = ../../../MyAppSpecificPath/**/*.{png,jpg,svg}``

(which is the correct number of directories up I need to go up to reach that path, works as expected)

OUTPUT_PATH = ${os.homedir()}/MyAppSpecificPath/build/``

Using the absolute path for OUTPUT works fine

How to overwrite?

If set INPUT and OUTPUT the same folder, will log

-------------
null
true
undefined
-------------

error: null, complete: true, statistic: undefined.
But the image file does not change.

completed is always false despite successfull compression

In the callback function, completed always returns false for me, but the compression seems to work (the compressed files are output in the correct directory) and when I turn on the statistic option, I can see the statistics about how much file size was saved.

Fix the return algorithm for the "jpg" engine

Fix the return algorithm for the "jpg" engine

358 Line

From

outputResultcallback(error, completed, input, path_out_new, enginejpg.jpg

To

outputResultcallback(error, completed, input, path_out_new, enginejpg.jpg.engine

false alert in statistics

While compressing svg files that have already been compressed manually via svgomg, with the statistic option turned on, I get the following alerts in the console:

 Compression algorithm: [svgo]
 [Alert] Your file has become more size!!!
 File was size: [3.83KB] | File have size: [3.83KB] | Compression: [+0%]

In my opintion, if the file size is exactly the same and hasn't really increased, there shouldn't be an alert.

compress-Images not getting installed on linux server

npm i -g compress-ima
npm WARN deprecated [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com
/gulpjs/gulp-util-ca3b1f9f9ac5

[email protected] postinstall /usr/lib/node_modules/compress-images/node_modules/cwebp-bin
node lib/install.js

⚠ EACCES: permission denied, mkdir '/usr/lib/node_modules/compress-images/node_modules/cwebp-bin/vendor'
⚠ cwebp pre-build test failed
ℹ compiling from source
✖ Error: EACCES: permission denied, mkdir '/usr/lib/node_modules/compress-images/node_modules/cwebp-bin/8dc9f2aa-ab97-4
16e-8b45-8bfa0ec8c89e'

[email protected] postinstall /usr/lib/node_modules/compress-images/node_modules/giflossy
node lib/install.js

⚠ EACCES: permission denied, mkdir '/usr/lib/node_modules/compress-images/node_modules/giflossy/vendor'
⚠ giflossy pre-build test failed
ℹ compiling from source
/usr/lib/node_modules/compress-images/node_modules/onetime/index.js:15
throw new Error(fnName + ' can only be called once.');
^

Error: callback() can only be called once.
at onetime (/usr/lib/node_modules/compress-images/node_modules/onetime/index.js:15:11)
at /usr/lib/node_modules/compress-images/node_modules/giflossy/node_modules/download/index.js:156:5
at ConcatStream. (/usr/lib/node_modules/compress-images/node_modules/concat-stream/index.js:37:43)
at ConcatStream.emit (events.js:203:15)
at finishMaybe (/usr/lib/node_modules/compress-images/node_modules/readable-stream/lib/_stream_writable.js:630:14)
at endWritable (/usr/lib/node_modules/compress-images/node_modules/readable-stream/lib/_stream_writable.js:638:3)
at ConcatStream.Writable.end (/usr/lib/node_modules/compress-images/node_modules/readable-stream/lib/_stream_writable.js:594:41)
at DuplexWrapper.onend (/usr/lib/node_modules/compress-images/node_modules/readable-stream/lib/_stream_readable.js:577:10)
at Object.onceWrapper (events.js:286:20)
at DuplexWrapper.emit (events.js:203:15)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: node lib/install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-08-07T12_25_44_410Z-debug.log

[pngquant] cannot open folder if its name contain cyrille

pngquant - Не сохраняет изображение если имя директории указано кириллицей.
Судя по всему эта проблема pngquant, но нужно будет проверить, и возможно нужно будет её обновить.

'Starting compress images'

File from: src/img/новая/lice.png
File to: build/img/новая/lice.png
Compression algorithm: [pngquant]
{ Error: Command failed: J:\Разные файлы\compress-images\node_modules\pngquant-b
in\vendor\pngquant.exe --quality=20-50 -o build/img/новая/lice.png src/img/новая
/lice.png
error: cannot open src\img\новая\lice.png for reading

at ChildProcess.exithandler (child_process.js:294:12)
at ChildProcess.emit (events.js:198:13)
at maybeClose (internal/child_process.js:982:16)
at Socket.stream.socket.on (internal/child_process.js:389:11)
at Socket.emit (events.js:198:13)
at Pipe._handle.close (net.js:606:12)

killed: false,
code: 2,
signal: null,
cmd:
'J:\Разные файлы\compress-images\node_modules\pngquant-bin\vendor\pngqu
ant.exe --quality=20-50 -o build/img/новая/lice.png src/img/новая/lice.png' }
[Error] Your file was not compressed!!!
[Error] You can see log to:./log/compress-images

'Compress images completed'
'Console will be close after [20] seconds...'

Update Dependencies

Hey! Thank you for your work on this awesome library. I've recently started using it and was surprised by the ease-of-use and good integrations.

After running yarn audit (will also apply to npm audit) I noticed that some dependencies were outdated (See below). Is an update planned or would you be open to a PR from me updating the dependencies?

┌───────────────┬──────────────────────────────────────────────────────────────┐
│ low           │ Denial of Service                                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ mem                                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=4.0.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > npm > libcipm > lock-verify > @iarna/cli > │
│               │ yargs > os-locale > mem                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1084                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ low           │ Denial of Service                                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ mem                                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=4.0.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > npm > libnpm > lock-verify > @iarna/cli >  │
│               │ yargs > os-locale > mem                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1084                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ low           │ Denial of Service                                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ mem                                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=4.0.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > npm > lock-verify > @iarna/cli > yargs >   │
│               │ os-locale > mem                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1084                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ yargs-parser                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=13.1.2 <14.0.0 || >=15.0.1 <16.0.0 || >=18.1.2             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > npm > libcipm > lock-verify > @iarna/cli > │
│               │ yargs > yargs-parser                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1500                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ yargs-parser                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=13.1.2 <14.0.0 || >=15.0.1 <16.0.0 || >=18.1.2             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > npm > libnpm > lock-verify > @iarna/cli >  │
│               │ yargs > yargs-parser                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1500                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ yargs-parser                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=13.1.2 <14.0.0 || >=15.0.1 <16.0.0 || >=18.1.2             │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > npm > lock-verify > @iarna/cli > yargs >   │
│               │ yargs-parser                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1500                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ high          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ trim-newlines                                                │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=3.0.1 <4.0.0 || >=4.0.1                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > cwebp-bin > logalot > squeak > lpad-align  │
│               │ > meow > trim-newlines                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1753                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ high          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ trim-newlines                                                │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=3.0.1 <4.0.0 || >=4.0.1                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > jpeg-recompress-bin > logalot > squeak >   │
│               │ lpad-align > meow > trim-newlines                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1753                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ high          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ trim-newlines                                                │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=3.0.1 <4.0.0 || >=4.0.1                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > jpegtran-bin > logalot > squeak >          │
│               │ lpad-align > meow > trim-newlines                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1753                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ high          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ trim-newlines                                                │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=3.0.1 <4.0.0 || >=4.0.1                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > mozjpeg > logalot > squeak > lpad-align >  │
│               │ meow > trim-newlines                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1753                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ high          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ trim-newlines                                                │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=3.0.1 <4.0.0 || >=4.0.1                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > pngcrush-bin > logalot > squeak >          │
│               │ lpad-align > meow > trim-newlines                            │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1753                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ high          │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ trim-newlines                                                │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=3.0.1 <4.0.0 || >=4.0.1                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > pngout-bin > logalot > squeak > lpad-align │
│               │ > meow > trim-newlines                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://www.npmjs.com/advisories/1753                        │
└───────────────┴──────────────────────────────────────────────────────────────┘
14 vulnerabilities found - Packages audited: 1197
Severity: 6 Low | 8 High
Done in 1.84s.

Error: ENOENT: no such file or directory

hi thanks for this great package , unfortunately it doesn't work with me i have several Centos servers i already try it on 3 servers have same result npm install goes well all package have green sign installed and pass the test when i run task with gulp it start normally after period give this massage i think it mean it doesn't create output for current fille

 File from: ./upload/blockmenu/ru/0_22643600_1473931384_img.jpg
 File to: ./testimg/blockmenu/ru/0_22643600_1473931384_img.jpg
 Compression algorithm: [mozjpeg]
 File was size: [41.37KB] | File have size: [19.96KB] | Compression: [51.76%]
-----------------------------------
 New directory was created: ./testimg/_source/catalog/ru/  
 New directory was created: ./testimg/_source/catalog/ru/  
 New directory was created: ./testimg/_source/catalog/ru/  
fs.js:110
    throw err;
    ^

Error: ENOENT: no such file or directory, stat './testimg/catalog/ru/0_12826300_1484311318.jpg'
    at Object.fs.statSync (fs.js:914:3)
    at getFilesizeInBytes (/var/www/vhosts/sitename.ru/httpdocs/node_modules/compress-images/index.js:1360:23)
    at /var/www/vhosts/sitename.ru/httpdocs/node_modules/compress-images/index.js:569:29
    at exithandler (child_process.js:289:5)
    at ChildProcess.errorhandler (child_process.js:301:5)
    at ChildProcess.emit (events.js:182:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:223:12)
    at onErrorNT (internal/child_process.js:394:16)
    at process._tickCallback (internal/process/next_tick.js:174:19)

npm i compress-images

Command isn't working. Output:

`npm WARN deprecated [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5

[email protected] postinstall /Users/smartnexus/Desktop/OrchestraManager/node_modules/cwebp-bin
node lib/install.js

✔ cwebp pre-build test passed successfully

[email protected] postinstall /Users/smartnexus/Desktop/OrchestraManager/node_modules/giflossy
node lib/install.js

✔ giflossy pre-build test passed successfully

[email protected] postinstall /Users/smartnexus/Desktop/OrchestraManager/node_modules/gifsicle
node lib/install.js

✔ gifsicle pre-build test passed successfully

[email protected] postinstall /Users/smartnexus/Desktop/OrchestraManager/node_modules/guetzli
node lib/install.js

⚠ The /Users/smartnexus/Desktop/OrchestraManager/node_modules/guetzli/vendor/guetzli binary doesn't seem to work correctly
⚠ guetzli pre-build test failed
ℹ compiling from source
✖ Error: mkdir -p /Users/smartnexus/Desktop/OrchestraManager/node_modules/guetzli/vendor && make && mv bin/Release/guetzli /Users/smartnexus/Desktop/OrchestraManager/node_modules/guetzli/vendor/guetzli
Command failed: make && mv bin/Release/guetzli /Users/smartnexus/Desktop/OrchestraManager/node_modules/guetzli/vendor/guetzli
Package libpng was not found in the pkg-config search path.
Perhaps you should add the directory containing libpng.pc' to the PKG_CONFIG_PATH environment variable No package 'libpng' found Package libpng was not found in the pkg-config search path. Perhaps you should add the directory containing libpng.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libpng' found
Package libpng was not found in the pkg-config search path.
Perhaps you should add the directory containing libpng.pc' to the PKG_CONFIG_PATH environment variable No package 'libpng' found Package libpng was not found in the pkg-config search path. Perhaps you should add the directory containing libpng.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libpng' found
Package libpng was not found in the pkg-config search path.
Perhaps you should add the directory containing libpng.pc' to the PKG_CONFIG_PATH environment variable No package 'libpng' found Package libpng was not found in the pkg-config search path. Perhaps you should add the directory containing libpng.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libpng' found
Package libpng was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpng.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libpng' found
guetzli/guetzli.cc:23:10: fatal error: 'png.h' file not found
#include "png.h"
^~~~~~~
1 error generated.
make[1]: *** [obj/Release/guetzli.o] Error 1
make: *** [guetzli] Error 2

at ChildProcess.exithandler (child_process.js:270:12)
at emitTwo (events.js:125:13)
at ChildProcess.emit (events.js:213:7)
at maybeClose (internal/child_process.js:927:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)

[email protected] postinstall /Users/smartnexus/Desktop/OrchestraManager/node_modules/jpeg-recompress-bin
node lib/install.js

✔ jpeg-recompress pre-build test passed successfully

[email protected] postinstall /Users/smartnexus/Desktop/OrchestraManager/node_modules/jpegoptim-bin
node lib/install.js

⚠ Command failed: /Users/smartnexus/Desktop/OrchestraManager/node_modules/jpegoptim-bin/vendor/jpegoptim --version
dyld: Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.9.dylib
Referenced from: /Users/smartnexus/Desktop/OrchestraManager/node_modules/jpegoptim-bin/vendor/jpegoptim
Reason: image not found

⚠ jpegoptim pre-build test failed
ℹ compiling from source
✖ Error: Command failed: /bin/sh -c ./configure --prefix="/Users/smartnexus/Desktop/OrchestraManager/node_modules/jpegoptim-bin/vendor" --bindir="/Users/smartnexus/Desktop/OrchestraManager/node_modules/jpegoptim-bin/vendor"

checking build system type... x86_64-apple-darwin18.2.0
checking host system type... x86_64-apple-darwin18.2.0
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
Angels-MacBook-Air:OrchestraManager smartnexus$ npm i compress-images
npm WARN deprecated [email protected]: gulp-util is deprecated - replace it, following the guidelines at https://medium.com/gulpjs/gulp-util-ca3b1f9f9ac5

[email protected] postinstall /Users/smartnexus/Desktop/OrchestraManager/node_modules/jpegoptim-bin
node lib/install.js

⚠ Command failed: /Users/smartnexus/Desktop/OrchestraManager/node_modules/jpegoptim-bin/vendor/jpegoptim --version
dyld: Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.9.dylib
Referenced from: /Users/smartnexus/Desktop/OrchestraManager/node_modules/jpegoptim-bin/vendor/jpegoptim
Reason: image not found

⚠ jpegoptim pre-build test failed
ℹ compiling from source
✖ Error: Command failed: /bin/sh -c ./configure --prefix="/Users/smartnexus/Desktop/OrchestraManager/node_modules/jpegoptim-bin/vendor" --bindir="/Users/smartnexus/Desktop/OrchestraManager/node_modules/jpegoptim-bin/vendor"

checking build system type... x86_64-apple-darwin18.2.0
checking host system type... x86_64-apple-darwin18.2.0
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking for a BSD-compatible install... /usr/bin/install -c
checking whether make sets $(MAKE)... yes
checking for jpeg_read_header in -ljpeg... no
Cannot find libjpeg or you have too old version (v6 or later required).

at Promise.all.then.arr (/Users/smartnexus/Desktop/OrchestraManager/node_modules/execa/index.js:231:11)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)

npm WARN [email protected] No description

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] postinstall: node lib/install.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
`

file does not exist when it does?

crawler/screenshots/19-07-2021/expedia.com-desktop.jpeg
crawler/screenshots/19-07-2021/
File does not exist!

when i run my screenshot code and then the compress i get it to print the

const INPUT_path_to_your_images = crawler/${partialPath.replace('../', '')}-desktop.jpeg;
const OUTPUT_path = crawler/screenshots/${date}/;

and

crawler/screenshots/19-07-2021/expedia.com-desktop.jpeg
crawler/screenshots/19-07-2021/

this gets printed out for them both which i can click and follow and they take me to the image and the folder its meant to be in but is erroring saying file doesnt exist??? does the compressing need a delay or something maybe the file is being saved and the code trys too fast to compress and doesnt find it in time?? any help would be great

How I can compress webp image format?

Hi !! This it is the code that I using, and I have some questions

  • How can I compress the webp image format?
    I am using this package in my project to compress and export the images from src folder to dist folder. But if any image is not compressed, it does not copy it to the dist folder, and therefore cannot find it.

  • And if it can be done, how do I do it? Why does this not work?
    { webp: { engine: 'webp', command: ['-quality', '60'] } },

/**
 * @function compressImages 
 * @description Minify size your images. Image compression with extension: jpg/jpeg, svg, png, gif, webp.
 * @param {string} inputPath Path of the images to compress
 * @param {string} outputPath Path of the folder to save the images compressed
 * @requires
 * @see {@link https://github.com/semiromid/compress-images}
 */


const compress_images = require('compress-images');

function compressImages(inputPath, outputPath) {
	compress_images(
		inputPath,
		outputPath,
		{ compress_force: false, statistic: true, autoupdate: true },
		false,

		{ jpg: { engine: 'mozjpeg', command: ['-quality', '60'] } },
		{ png: { engine: 'pngquant', command: ['--quality=20-50'] } },
		{ svg: { engine: 'svgo', command: ['--multipass'] } },
		{ gif: { engine: 'gifsicle', command: ['--colors', '64', '--use-col=web'] } },
		{ webp: { engine: 'webp', command: ['-quality', '60'] } },
		function (error) {
			if (error === null) {
				console.error("Success!!");
			} else {
				console.error("Error: " + error);
			}
		}
	);
}

compressImages('static/src/images/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif,webp}', 'static/dist/images/');

Suggestions to avoid passing excessive arguments and use well-constructed options

Hi @semiromid

I have some suggestions about the types of parameters and their usages.

Quoting from README.md

const compress_images = require("compress-images");

function MyFun() {
  compress_images(
    "src/img/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}",
    "build/img/",
    { compress_force: false, statistic: true, autoupdate: true },
    false,
    { jpg: { engine: "mozjpeg", command: ["-quality", "60"] } },
    { png: { engine: "pngquant", command: ["--quality=20-50", "-o"] } },
    { svg: { engine: "svgo", command: "--multipass" } },
    {
      gif: { engine: "gifsicle", command: ["--colors", "64", "--use-col=web"] },
    },
    function (err, completed) {
      if (completed === true) {
        // Doing something.
      }
    }
  );
}

Don't get me wrong but passing arguments that may don't even do with the input files, it's just kind of confusing and doesn't seem like it's well constructed.


What do you think about changing the structure to have something like this instead?

PS: Suggestions are written in TypeScript to have a better understanding of the properties and their types.
You can review them on the TS Playground

type PropsType = {
  output?: string;
  compress_force?: boolean;
  statistic?: boolean;
  autoupdate?: boolean;
  /** @default "./log/compress-images" */
  pathLog?: string;
  globoption?: boolean;
  compressors: {
    jpg?:
      | {
          engine: "jpegtran";
          /**
           * @example ['-trim', '-progressive', '-copy', 'none', '-optimize']
           * @see https://libjpeg-turbo.org/
           */
          command?: string[];
        }
      | {
          engine: "mozjpeg";
          /**
           * @example ['-quality', '10']
           * @see https://github.com/mozilla/mozjpeg/
           */
          command?: string[];
        }
      | {
          engine: "webp";
          /**
           * @example ['-q', '60']
           * @see https://developers.google.com/speed/webp/
           */
          command?: string[];
        }
      | {
          engine: "guetzli";
          /**
           * @example ['--quality', '84']
           * @see https://github.com/google/guetzli/
           * @description (Very long compresses on Win 8.1 https://github.com/google/guetzli/issues/238)
           */
          command?: string[];
        }
      | {
          engine: "jpegRecompress";
          /**
           * @example ['--quality', 'high', '--min', '60']
           * @see https://github.com/danielgtaylor/jpeg-archive/
           */
          command?: string[];
        }
      | {
          engine: "jpegoptim";
          /**
           * @example ['--all-progressive', '-d']
           * @see https://github.com/imagemin/jpegoptim-bin
           * @description To use jpegoptim you must npm install jpegoptim-bin --save, this library does not work properly on some OS and platforms. from https://github.com/imagemin/jpegoptim-bin Issues! May be a problems with installation and use on Win 7 x32 and maybe other OS: compress-images - issues/21 Caution! if do not specify '-d' all images will be compressed in the source folder and will be replaced. For Windows x32 and x63 also, you can use https://github.com/vikas5914/jpegoptim-win. Copy jpegoptim-32.exe and replace and rename in "node_modules\jpegoptim-bin\vendor\jpegoptim.exe"
           */
          command?: string[];
        }
      | {
          engine: "tinify";
          /**
           * @example ['copyright', 'creation', 'location']
           * @see https://tinypng.com/developers/reference/nodejs/
           */
          command?: string[];
          /**
           * @example "sefdfdcv335fxgfe3qw"
           */
          key?: string;
        };
    png?:
      | {
          engine: "pngquant";
          /**
           * @example ['--quality=20-50', '-o']
           * @see https://pngquant.org/
           * @description If you want to compress in the same folder, as example: ['--quality=20-50', '--ext=.png', '--force']. To use this library you need to install it manually. It does not work properly on some OS (Win 7 x32 and maybe other). npm install pngquant-bin --save Quality should be in format min-max where min and max are numbers in range 0-100. Can be problems with cyrillic filename issues/317
           */
          command?: string[];
        }
      | {
          engine: "optipng";
          /**
           * @see http://optipng.sourceforge.net/
           */
          command?: string[];
        }
      | {
          engine: "pngout";
          /**
           * @see http://advsys.net/ken/util/pngout.htm
           */
          command?: string[];
        }
      | {
          engine: "webp";
          /**
           * @example ['-q', '60']
           * @see https://developers.google.com/speed/webp/
           */
          command?: string[];
        }
      | {
          engine: "pngcrush";
          /**
           * @example ['-reduce', '-brute']
           * @see https://pmt.sourceforge.io/pngcrush/
           * @description (It does not work properly on some OS)
           */
          command?: string[];
        }
      | {
          engine: "tinify";
          /**
           * @example ['copyright', 'creation', 'location']
           * @see https://tinypng.com/developers/reference/nodejs/
           */
          command?: string[];
          /**
           * @example "sefdfdcv335fxgfe3qw"
           */
          key?: string;
        };
    gif?:
      | {
          engine: "gifsicle";
          /**
           * @example ['--colors', '64', '--use-col=web'] or ['--optimize']
           * @see http://www.lcdf.org/gifsicle/
           * @description To use this library you need to install it manually. It does not work properly on some OS. npm install gifsicle --save
           */
          command?: string[];
        }
      | {
          engine: "giflossy";
          /**
           * @example ['--lossy=80']
           * @see http://www.lcdf.org/gifsicle/
           * @description For Linux x64 and Mac OS X
           */
          command?: string[];
        }
      | {
          engine: "";
          /**
           * @example ['-f', '80', '-mixed', '-q', '30', '-m', '2']
           * @see https://developers.google.com/speed/webp/docs/gif2webp
           */
          command?: string[];
        };
    svg?: {
      engine: "svgo";
      /**
       * @example '--multipass'
       * @see https://www.npmjs.com/package/svgo/
       */
      command?: string;
    };
  };
};

// I can't find their types on the README.md so they are optional and have "any"
type StatisticType = {
  input?: any;
  path_out_new?: any;
  algorithm?: any;
  size_in?: any;
  size_output?: any;
  percent?: any;
  err?: any;
};

type CallbackType = (
  error: Error | null,
  status: boolean,
  statistic: StatisticType,
) => void;

type PromiseReturnType = {
  status: boolean;
  statistic: StatisticType;
};

function compressImages(
  path: string,
  props: PropsType,
): Promise<PromiseReturnType>;
function compressImages(
  path: string,
  props: PropsType,
  callback: CallbackType,
): void;
function compressImages(
  path: string,
  props: PropsType,
  callback?: CallbackType,
): void | Promise<PromiseReturnType> {
  console.log(path);
  console.log(props);

  if (!callback) {
    return Promise.resolve({
      status: true,
      statistic: {},
    });
  }

  callback(Error(), true, {});

  return undefined;
}

(async () => {
  // Example usage with callback
  compressImages(
    "src/img/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}",
    {
      output: "build/img/",
      compress_force: false,
      statistic: true,
      autoupdate: true,
      compressors: {
        jpg: { engine: "mozjpeg", command: ["-quality", "60"] },
        png: { engine: "pngquant", command: ["--quality=20-50", "-o"] },
        svg: { engine: "svgo", command: "--multipass" },
        gif: {
          engine: "gifsicle",
          command: ["--colors", "64", "--use-col=web"],
        },
      },
    },
    (error, status, statistic) => {
      console.log(error);
      console.log(status);
      console.log(statistic);
    },
  );

  // Example usage with Promise
  try {
    const { statistic, status } = await compressImages(
      "src/img/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}",
      {
        output: "build/img/",
        compress_force: false,
        statistic: true,
        autoupdate: true,
        compressors: {
          jpg: { engine: "mozjpeg", command: ["-quality", "60"] },
          png: { engine: "pngquant", command: ["--quality=20-50", "-o"] },
          svg: { engine: "svgo", command: "--multipass" },
          gif: {
            engine: "gifsicle",
            command: ["--colors", "64", "--use-col=web"],
          },
        },
      },
    );

    console.log(status);
    console.log(statistic);
  } catch (error) {
    console.error(error);
  }
})();

Does it protect itself from zip bombs ?

I really don't know anything about image extensions and encoding/compression.

But I believe some extensions are a form of compress, and when there is compression, there is potential attack of compression algorithm.

it is possible to set compress image size?

I want to set the size of the compressed image, for example, my images original size is 1.5 MB, or 2 MB, etc.
but compressed image size should be fixed like 6KB.

please let me know if it possible

npm audit

npm version - 6.1.0
node version - 10.6.0

│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > cwebp-bin > bin-build > download > caw >   │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > cwebp-bin > bin-wrapper > download > caw > │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > giflossy > bin-build > download > caw >    │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > giflossy > bin-wrapper > download > caw >  │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > gifsicle > bin-build > download > caw >    │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > gifsicle > bin-wrapper > download > caw >  │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > guetzli > bin-build > download > caw >     │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > guetzli > bin-wrapper > download > caw >   │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > jpeg-recompress-bin > bin-wrapper >        │
│               │ download > caw > tunnel-agent                                │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > jpegoptim-bin > bin-build > download > caw │
│               │ > tunnel-agent                                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > jpegoptim-bin > bin-wrapper > download >   │
│               │ caw > tunnel-agent                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > jpegtran-bin > bin-build > download > caw  │
│               │ > tunnel-agent                                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > jpegtran-bin > bin-wrapper > download >    │
│               │ caw > tunnel-agent                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > mozjpeg > bin-wrapper > download > caw >   │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > optipng-bin > bin-build > download > caw > │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > optipng-bin > bin-wrapper > download > caw │
│               │ > tunnel-agent                                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > pngcrush-bin > bin-build > download > caw  │
│               │ > tunnel-agent                                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > pngcrush-bin > bin-wrapper > download >    │
│               │ caw > tunnel-agent                                           │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > pngout-bin > bin-wrapper > download > caw  │
│               │ > tunnel-agent                                               │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://nodesecurity.io/advisories/598                       │
└───────────────┴──────────────────────────────────────────────────────────────┘```

Please let me know if I can be of any help.

TypeError: Cannot read property 'engine' of undefined

excuse me, I am a newbie and I used win10.

  1. I install pngquant Binary for Windows (v2.11.7)
  2. I don't add pngquant to PATH environment variable, but I set "bin" params in package.json, linke this:
{
   "name": "my-blog-backend",
   "bin": {
         "pngquant": "D:\\chrome下载\\pngquant-windows\\pngquant\\pngquant.exe"
  },
}

then used
npm link

  1. I refer to your code and running it

result:

TypeError: Cannot read property 'engine' of undefined

how I could use pngquant with Node.js , thanks very much

multiple image extension not accepting for single image and callback too not working

var imagedir1=./public/uploads/b362bec6-52ce-42dc-a8a9-01a227adedd6.jpg
compress_images(imagedir1, './public/uploads/', {compress_force: false, statistic: true, autoupdate: true}, false,
{jpg: {engine: 'mozjpeg', command: ['-quality', '75']}},
{png: {engine: 'pnquant', command: false}},
{svg: {engine: false, command: false}},
{gif: {engine: false, command: false}},function(res){
console.log(res) //not working
// fs.unlink(imagedir1);
});

Grunt contrib

Hello,

I would like to know if you have or to consider contrib for grunt usage ?

thx

[FR] Allow to cache already compressed images.

Background

I created a little workflow with your tool, where our DEVs copy images first in am uncompressed folder and have to run the command to compress and copy the files to the final folder. That is rather a tedious job, as it is not as easy as just copy the file directly into the folder.

Now I came up with the idea, that the compression could be done in the final folder already. We could then include this step just in our release. But then we would need to take care, that no double compression is done.

Including the compression of all images, in each release, is no option, as it would take way too long.

Feature Request

For gulp as an example, there is a plugin gulp-cache. It just creates a file which keeps an index of all already cached images. So there would be no double compression. I would wish for a similar (optional) approach for your tool too :)

Support to Typescript

I was working with javascript, but I have decided to migrate to TypeScript, and I don't want to leave this plugin abandoned, when will you give it support for Ts?

Get an error during installing module

I can't install compress-images because of getting an error:

npm ERR! code 1
npm ERR! path /home/khuzha/work/verifydocs/node_modules/guetzli
npm ERR! command failed
npm ERR! command sh -c node lib/install.js
npm ERR! ⚠ Command failed: /home/khuzha/work/verifydocs/node_modules/guetzli/vendor/guetzli --verbose
npm ERR! Guetzli JPEG compressor. Usage: 
npm ERR! guetzli [flags] input_filename output_filename
npm ERR! 
npm ERR! Flags:
npm ERR!   --verbose    - Print a verbose trace of all attempts to standard output.
npm ERR!   --quality Q  - Visual quality to aim for, expressed as a JPEG quality value.
npm ERR!   --memlimit M - Memory limit in MB. Guetzli will fail if unable to stay under
npm ERR!                  the limit. Default is 6000 MB
npm ERR!   --nomemlimit - Do not limit memory usage.
npm ERR! 
npm ERR! 
npm ERR!   ⚠ guetzli pre-build test failed
npm ERR!   ℹ compiling from source
npm ERR!   ✔ guetzli built successfully
npm ERR! /home/khuzha/work/verifydocs/node_modules/execa/index.js:231
npm ERR!                                err = new Error(`Command failed: ${joinedCmd}${output}`);
npm ERR!                                      ^
npm ERR! 
npm ERR! Error: Command failed: /bin/sh -c make && mv bin/Release/guetzli /home/khuzha/work/verifydocs/node_modules/guetzli/vendor/guetzli
npm ERR! /bin/sh: 1: make: not found
npm ERR! 
npm ERR! 
npm ERR!     at /home/khuzha/work/verifydocs/node_modules/execa/index.js:231:11
npm ERR!     at processTicksAndRejections (node:internal/process/task_queues:94:5) {
npm ERR!   code: 127,
npm ERR!   killed: false,
npm ERR!   stdout: '',
npm ERR!   stderr: '/bin/sh: 1: make: not found\n',
npm ERR!   failed: true,
npm ERR!   signal: null,
npm ERR!   cmd: '/bin/sh -c make && mv bin/Release/guetzli /home/khuzha/work/verifydocs/node_modules/guetzli/vendor/guetzli',
npm ERR!   timedOut: false
npm ERR! }

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/khuzha/.npm/_logs/2021-02-02T14_51_45_233Z-debug.log

I uploaded full log here: https://gist.github.com/Khuzha/633139908108848f55361fef3914da6e

Is it possible to resize ?

Context

I have a very limited memory environment, and I don't want to implement at least for now any third party storage for my images.
I am trying to compress as much as possible. For this, I am limiting uploads to 2 MB which seems very limited as I accept captures from modern smartphones. As a result, I want to raise the limit to say 4 MB, but instantly compress as much as possible.

Resize

I want to resize images and keep ration, say limit to 512px for width and let length relate to that keeping ratio

There are some solution like Sharp

However I am afraid to do it badly, like resize after compression or before ?! also I'm afraid about extensions as I don't know much (and I want to accept most image extensions).

Any guidelines ?

Thanks a lot !

Error: Command failed: /bin/sh -c make install

I am using this npm in my windows 10 system, it is running in local perfectly.
On my server, there is Ubuntu 18.04, I am unable to install this package. As it ends with below mentioned error. Do you have any idea ?

Response code 404 (Not Found)
⚠ gifsicle pre-build test failed
ℹ compiling from source
✖ Error: Command failed: /bin/sh -c make install
/bin/sh: 1: make: not found

npm warning - decompress, braces and minimist

Hey, just installed the package and the npm audit gives me some moderate and high vulnerabilities with this projects dependencies. They are all solved in newer versions, I was wondering if there is any fix on the backlog for this?

Thanks in advance!

                                                            
                      === npm audit security report ===                        
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > giflossy > bin-build > download > caw >    │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/598                             │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Moderate      │ Memory Exposure                                              │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.6.0                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > giflossy > bin-wrapper > download > caw >  │
│               │ tunnel-agent                                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/598                             │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ braces                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=2.3.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > giflossy > bin-build > decompress >        │
│               │ vinyl-fs > glob-stream > micromatch > braces                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/786                             │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ braces                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=2.3.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > giflossy > bin-build > download >          │
│               │ gulp-decompress > decompress > vinyl-fs > glob-stream >      │
│               │ micromatch > braces                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/786                             │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ braces                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=2.3.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > giflossy > bin-wrapper > download >        │
│               │ gulp-decompress > decompress > vinyl-fs > glob-stream >      │
│               │ micromatch > braces                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/786                             │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ braces                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=2.3.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > giflossy > bin-build > download > vinyl-fs │
│               │ > glob-stream > micromatch > braces                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/786                             │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Regular Expression Denial of Service                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ braces                                                       │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=2.3.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > giflossy > bin-wrapper > download >        │
│               │ vinyl-fs > glob-stream > micromatch > braces                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/786                             │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.2.1 <1.0.0 || >=1.2.3                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > mkdirp > minimist                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1179                            │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ Low           │ Prototype Pollution                                          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ minimist                                                     │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=0.2.1 <1.0.0 || >=1.2.3                                    │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > mocha > mkdirp > minimist                  │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1179                            │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Arbitrary File Write                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ decompress                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=4.2.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > giflossy > bin-build > decompress          │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1217                            │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Arbitrary File Write                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ decompress                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=4.2.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > giflossy > bin-build > download >          │
│               │ gulp-decompress > decompress                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1217                            │
└───────────────┴──────────────────────────────────────────────────────────────┘
┌───────────────┬──────────────────────────────────────────────────────────────┐
│ High          │ Arbitrary File Write                                         │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Package       │ decompress                                                   │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Patched in    │ >=4.2.1                                                      │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Dependency of │ compress-images [dev]                                        │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ Path          │ compress-images > giflossy > bin-wrapper > download >        │
│               │ gulp-decompress > decompress                                 │
├───────────────┼──────────────────────────────────────────────────────────────┤
│ More info     │ https://npmjs.com/advisories/1217                            │
└───────────────┴──────────────────────────────────────────────────────────────┘

await for compress_images

How can I use promise with compress-images? My code is something like this, This is return resolve before complete image-compress process.
`
let compressImage = (UploadDir, contentType) => {
return new Promise((resolve, reject) => {
let INPUT_path_to_your_images = UploadDir + '*.{jpg,JPG,jpeg,JPEG,png,svg,gif}';
let OUTPUT_path = './public/uploads/compressed/';
if (!fs.existsSync(OUTPUT_path)) {
fs.mkdirSync(OUTPUT_path);
}

		compress_images(INPUT_path_to_your_images, OUTPUT_path, {compress_force: false, statistic: true, autoupdate: true}, false,
            {jpg: {engine: 'mozjpeg', command: ['-quality', '60']}},
            {png: {engine: 'pngquant', command: ['--quality=20-50']}},
            {svg: {engine: 'svgo', command: '--multipass'}},
            {gif: {engine: 'gifsicle', command: ['--colors', '64', '--use-col=web']}},
            function(err){
                if(err){
                    return reject(err);
                }
            });
        return resolve({OUTPUT_path : OUTPUT_path, msg: 'Image compression is done.'});
    });
};

`

use pngquant to compress png

`execFile(pngquant, array, function (err) {

        if(option.statistic){
          //Block statistic
          //- - - - - - - - - - - - -  - - - - - - - - - - -
          //Узнаем размер файла после сжатия
          size_output = getFilesizeInBytes(output);
          
          //Находим на сколько процентов удалось сжать файл
          percent = size_output / size_in;
          percent = percent * 100;
          percent = 100 - percent;
          percent = Math.round(percent * 100) / 100;

          return callback(size_in, size_output, percent);  
          //- - - - - - - - - - - - -  - - - - - - - - - - -
        }
    }); `

This code in index.js file may throw an errs, because the param of --quality min-max.
If conversion results in quality below the min quality the image won't be saved ,so when I set statistic == true ,the function getFilesizeInBytes(output) may throw an err, because there is no output file can be found.

Vulnerabilities

Some dependencies have vulnerabilities.

` High Prototype Pollution

Package dot-prop

Patched in >=5.1.1

Dependency of compress-images [dev]

Path compress-images > npm > update-notifier > configstore >
dot-prop

More info https://npmjs.com/advisories/1213`

T

Mistake

Get error when compress single image

Hi, If i try to compress single image I get this error.

You do not turned on [enginepng] and you set to path extension 'png', delete extension it 'png' from pat
h, or turn on [enginepng: ['pngquant'] or ['optipng'] or ['webp'] or other].  OR you set had path don't r
ight!: Examples: src/img/**/*.{jpg,JPG,jpeg,JPEG,png} or src/img/**/*.png or src/img/*.png ...
 Your path: uploads/avatar-1536061045908.jpg

But if I update input source to
./uploads/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}
then it was working fine

Here is my complete code. req.file.path is the path of image i get after file was uploaded

compress_images(req.file.path, 'compress/', 
        {compress_force: true, statistic: true, autoupdate: true}, false,
        {jpg: {engine: 'mozjpeg', command: ['-quality', '60']}},
        {png: {engine: 'pngquant', command: ['--quality=20-50']}},
        {svg: {engine: 'svgo', command: '--multipass'}},
        {gif: {engine: 'gifsicle', command: ['--colors', '64', '--use-col=web']}}, function(){});

Input image from memory

I see the examples load the images from a directory, is it possible to input the images from memory and outputting them similarly? Thanks

Error of inputting path

I'm trying to use the example #7, but for reason I get this error message below:

 You didn't turn on [enginejpg], but your input path includes the 'jpg' extension; either delete the extension 'jpg' from the input path, or turn on [enginejpg: ['jpegtran'] or ['mozjpeg'] or ['webp'] or other]. Alternatively, your input path may be malformed!: Examples: src/img/**/*.{jpg,JPG,jpeg,JPEG,png} or src/img/**/*.jpg or src/img/*.jpg ...
 Input path: ../../img/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}

This is literally the same code as above. The only difference is that is the input and out destination:

const compress_images = require('compress-images');
let INPUT_path_to_your_images;
let OUTPUT_path;

INPUT_path_to_your_images = '../../img/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}';
OUTPUT_path = '../../img/';

compress_images(
  INPUT_path_to_your_images,
  OUTPUT_path,
  { compress_force: true, statistic: false, autoupdate: true },
  false,
  { jpg: { engine: false, command: false } },
  { png: { engine: 'pngquant', command: ['--quality=20-50', '--ext=-min.png', '--force'] } },
  { svg: { engine: false, command: false } },
  { gif: { engine: false, command: false } },
  function (err, completed, statistic) {
    if (err === null) {
      fs.unlink(statistic.input, (err) => {
        if (err) throw err;
        console.log('successfully compressed and deleted ' + statistic.input);
      });
    }
  }
);

I don't really understand what I need to fix based on the error message, since I can't see any examples of the manual documentation regarding for example the [enginejpg].

What is there something I'm missing here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.