Skip to content

Commit

Permalink
1.9.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuriy-Svetlov committed Aug 20, 2020
1 parent 5bcedf4 commit a15d82e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
37 changes: 30 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ OUTPUT_path = "build/img/";

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"] } },
{ png: { engine: "pngquant", command: ["--quality=20-50", "-o"] } },
{ svg: { engine: "svgo", command: "--multipass" } },
{ gif: { engine: "gifsicle", command: ["--colors", "64", "--use-col=web"] } },
function (error, completed, statistic) {
Expand All @@ -99,7 +99,7 @@ function MyFun() {
{ compress_force: false, statistic: true, autoupdate: true },
false,
{ jpg: { engine: "mozjpeg", command: ["-quality", "60"] } },
{ png: { engine: "pngquant", command: ["--quality=20-50"] } },
{ png: { engine: "pngquant", command: ["--quality=20-50", "-o"] } },
{ svg: { engine: "svgo", command: "--multipass" } },
{
gif: { engine: "gifsicle", command: ["--colors", "64", "--use-col=web"] },
Expand Down Expand Up @@ -220,7 +220,7 @@ compress_images('src/img/source/**/*.{jpg,JPG,jpeg,JPEG,gif,png,svg}', 'build/im
//[png] ---to---> [png(pngquant)] WARNING!!! autoupdate - recommended to turn this off, it's not needed here - autoupdate: false
compress_images('src/img/source/**/*.png', 'build/img/', {compress_force: false, statistic: true, autoupdate: false}, false,
{jpg: {engine: false, command: false}},
{png: {engine: 'pngquant', command: ['--quality=30-60']}},
{png: {engine: 'pngquant', command: ['--quality=30-60', '-o']}},
{svg: {engine: false, command: false}},
{gif: {engine: false, command: false}}, function(){
});
Expand Down Expand Up @@ -250,7 +250,7 @@ As an example, one of many:

compress_images(INPUT_path_to_your_images, OUTPUT_path, {compress_force: false, statistic: true, autoupdate: true, pathLog: './log/lib/compress-images'}, false,
{jpg: {engine: 'jpegRecompress', command: ['--quality', 'high', '--min', '60']}},
{png: {engine: 'pngquant', command: ['--quality=20-50']}},
{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(err !== null){
Expand All @@ -276,7 +276,30 @@ As an example, one of many:
});
```

#### Example 7

Compressing an image in the same folder

```javascript
const
compress_images = require('compress-images'),
fs = require('fs'),
INPUT_path_to_your_images = 'src/img/**/!(*-min).png',
OUTPUT_path = 'src/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);
});
}
});
```

```html
<picture>
Expand Down Expand Up @@ -338,7 +361,7 @@ As an example, one of many:
+ **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.
+ For **pngquant** - `['--quality=20-50']` - 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`
+ For **pngquant** - `['--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](https://github.com/kornelski/pngquant/issues/317)
In details:
[pngquant](https://pngquant.org/) and
Expand Down Expand Up @@ -419,7 +442,7 @@ returns:
destination: OUTPUT_path,
enginesSetup: {
jpg: { engine: 'mozjpeg', command: ['-quality', '60']},
png: { engine: 'pngquant', command: ['--quality=20-50']},
png: { engine: 'pngquant', command: ['--quality=20-50', '-o']},
}
});

Expand All @@ -446,7 +469,7 @@ Using `onProgress`
onProgress,
enginesSetup: {
jpg: { engine: 'mozjpeg', command: ['-quality', '60']},
png: { engine: 'pngquant', command: ['--quality=20-50']},
png: { engine: 'pngquant', command: ['--quality=20-50', '-o']},
}
});

Expand Down
2 changes: 1 addition & 1 deletion example/compress_images.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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']}},
{png: {engine: 'pngquant', command: ['--quality=20-50', '-o']}},
{svg: {engine: 'svgo', command: '--multipass'}},
{gif: {engine: 'gifsicle', command: ['--colors', '64', '--use-col=web']}}, function(){
});
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,11 @@ var index = function (input, output, option, findfileop, enginejpg, enginepng, e
*/
var array;
if(false != enginepng.png.command){
array = enginepng.png.command.concat(['-o', output, input]);
if(enginepng.png.command.includes('-o')){
array = enginepng.png.command.concat([output, input]);
}else{
array = enginepng.png.command.concat([input]);
}
}else{
array = ['-o', output, input];
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "compress-images",
"version": "1.9.3",
"version": "1.9.4",
"description": "Minify size your images. Image compression with extension: jpg/jpeg, svg, png, gif.",
"keywords": [
"image-compress",
Expand Down

0 comments on commit a15d82e

Please sign in to comment.