Search code examples
node.jsimage-compressionimagemin

How use compress-images?


How use compress-images?

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

Gif image was - 4.1mb;

Gif image became - 4.2mb;

Gif image after compression is obtained more size than before. Why?

I try:

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=0-20']}},
                                                {svg: {engine: 'svgo', command: '--multipass'}},
                                                {gif: {engine: 'gifsicle', command: false}});

Solution

  • I can't tell why the size increased. I guess the algorithm doesn't work as we want it to work with default parameters.

    To compress the gif you have to look at the gifsicle manual and find the correct parameters for your use case. You can for example reduce the colors or the size of the image:

    --colors 16

    --scale 0.7

    Supply them as arguments to the command field.

    You can also change to another alogrithm such as giflossy or gif2webp.