Minify size your images. Image compression with extension: jpg/jpeg, svg, png, gif. NodeJs
Minify size your images. Image compression with extension: jpg/jpeg, svg, png, gif. NodeJs
compress-images Minify size your images. Image compression with extension: jpg/jpeg, svg, png, gif.
Minify size your images. Image compression with extension: jpg/jpeg, svg, png, gif.
You can also use:
You can use different algorithms and methods for compressing images with many options.
jpegtran, mozjpeg, webp, guetzli, jpegRecompress, jpegoptim, tinify;pngquant, optipng, pngout, webp, pngcrush, tinify;svgo;gifsicle, giflossy, gif2webp;You can even minify images by using a combination of compression algorithms. As an example -
mozjpeg+jpegoptimorjpegtran+mozjpegor any other algorithm.
If you get an error, the error log will be saved. Default path
./log/compress-images.
If you get an error, alternative algorithms for compressing images can be used. As an example: you want to compress images in
jpegRecompress, but you get the error Unsupported color conversion request, so an alternative algorithm to compress the images can be used, likemozjpeg.
You can specify the path to source images folder and all images in the folder will be compressed and moved to output folder.
As an example, one of many:
INPUT ['src/img/source/**/*.{jpg,JPG,jpeg,JPEG,gif,png,svg}']
OUTPUT ['build/img/']You should have in your path slash: /.
If you have slash \ it may be to replaced: input.replace(/\\/g, '/');
Other useful plugins:
npm install compress-images --save-devhttps://github.com/semiromid/compress-images/tree/master/example
……………Sometimes you could get errors, and then use alternative configuration "compress-images". As an example, one of many:
If you get an error from 'jpegRecompress', for example, the error "Unsupported color conversion request". In this case, an alternative image compression algorithm will be used.
An error log will be created at path './log/lib/compress-images'.
The algorithm 'mozjpeg' will attempt to be used instead.
…Compressing an image in the same folder (currently this only works with 'pngquant')
…
compress_images(input, output, option, globoption, enginejpg, enginepng, enginesvg, enginegif, callback)
input (type:string): Path to source image or images;
Example:
1. `'src/img/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}'`;
2. `'src/img/**/*.jpg'`;
3. `'src/img/*.jpg'`;
4. `'src/img/myimagename.jpg'`;
output (type:string): Path to compress images;
Example:
1. `'build/img/'`;
option (type:plainObject): Options module`s «compress-images»;
compress_force (type:boolean): Force compress images already compressed images true or false;
statistic (type:boolean): show image compression statistics true or false;
pathLog (type:string): Path to log file. Default is ./log/compress-images;
autoupdate (type:boolean): Auto-update module «compress_images» to the latest version true or false;
Example:
1. `{compress_force: false, statistic: true, autoupdate: true}`;globoption (type:boolean|other): Options module`s glob. Also you can set false;
enginejpg (type:plainObject): Engine for compressing jpeg and options compress. Key to be jpg;
engine (type:string): Engine for compressing jpeg. Possible values:
jpegtran,mozjpeg, webp, guetzli, jpegRecompress, jpegoptim, tinify;
command (type:boolean|array): Options for compression. Can be false or commands array.
For jpegtran - ['-trim', '-progressive', '-copy', 'none', '-optimize'] in details; jpegtran;
For mozjpeg - ['-quality', '10'] in details mozjpeg;
For webp - ['-q', '60'] in details webp;
For guetzli - ['--quality', '84'] (Very long compresses on Win 8.1 https://github.com/google/guetzli/issues/238) in details guetzli;
To use guetzli you must npm install guetzli --save, this library does not work properly on some OS and platforms.
For jpegRecompress - ['--quality', 'high', '--min', '60'] in details jpegRecompress;
For jpegoptim - ['--all-progressive', '-d']
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"
For tinify - ['copyright', 'creation', 'location'] In details tinify;
key (type:string): Key used for engine tinify. In details; tinify;
Example:
1. `{jpg: {engine: 'mozjpeg', command: ['-quality', '60']}`;
2. `{jpg: {engine: 'tinify', key: "sefdfdcv335fxgfe3qw", command: ['copyright', 'creation', 'location']}}`;
3. `{jpg: {engine: 'tinify', key: "sefdfdcv335fxgfe3qw", command: false}}`;enginepng (type:plainObject): Engine for compressing png and options for compression. Key to be png;
engine (type:string): Engine for compressing png. Possible values:
pngquant,optipng, pngout, webp, pngcrush, tinify;
command (type:boolean|array): Options for compression. Can be false or commands array.
['--quality=20-50', '-o'] 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
In details:
pngquant and
pngquant-bin - wrappernpm install --save optipng-bin in details optipng-bin - wrapper
and optipng;['-q', '60'] in details webp;['-reduce', '-brute'] in details pngcrush;['copyright', 'creation', 'location'] in details tinify;key (type:string): Key used for engine tinify. In details; tinify;
Example:
1. `{png: {engine: 'webp', command: ['-q', '100']}`;
2. `{png: {engine: 'tinify', key: "sefdfdcv335fxgfe3qw", command: ['copyright', 'creation', 'location']}}`;
3. `{png: {engine: 'optipng', command: false}}`;enginesvg (type:plainObject): Engine for compressing svg and options for compression. Key to be svg;
svgo; false or commands type string.For svgo - '--multipass' in details svgo;
Example:
1. `{svg: {engine: 'svgo', command: '--multipass'}`;
2. `{svg: {engine: 'svgo', command: false}}`;enginegif (type:plainObject): Engine for compressing gif and options for compression. Key to be gif;
gifsicle, giflossy, gif2webp; false or commands type array.It does not work properly on some OS. npm install gifsicle --save.
Example options:
['--colors', '64', '--use-col=web'] or ['--optimize'] In details gifsicle;
+ For giflossy - (For Linux x64 and Mac OS X) ['--lossy=80'] In details giflossy;
+ For gif2webp - ['-f', '80', '-mixed', '-q', '30', '-m', '2'] in details gif2webp;
Example:
1. `{gif: {engine: 'gifsicle', command: ['--colors', '64', '--use-col=web', '--scale', ' 0.8']}}`;
2. `{gif: {engine: 'giflossy', command: false}}`;
3. `{gif: {engine: 'gif2webp', command: ['-f', '80', '-mixed', '-q', '30', '-m', '2']}}`;true - result completed.false - result not completed.inputpath_out_newalgorithmsize_insize_outputpercenterr…Using onProgress
…promise/compress(params)
No open issues yet, or sync has not completed.