GithubHelp home page GithubHelp logo

Comments (5)

Yuriy-Svetlov avatar Yuriy-Svetlov commented on May 19, 2024

Hello, Zgj233.
Thank you for your question.

You need do:

open console and enter command
npm install compress-images --save-dev

create to file in you folder, as expamle : img_min.js

Open img_min.js and paste sourse code

    var compress_images = require('compress-images'), INPUT_path_to_your_images, OUTPUT_path;

    INPUT_path_to_your_images = 'src/img/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}';
    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']}},
                                                {svg: {engine: 'svgo', command: '--multipass'}},
                                                {gif: {engine: 'gifsicle', command: ['--colors', '64', '--use-col=web']}}, function(){
    });

4.create dir and put you images
src/img/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}

5.Create dir
build/img/ or build/

As example, open console and enter command:
node img_min.js

from compress-images.

Yuriy-Svetlov avatar Yuriy-Svetlov commented on May 19, 2024

You can to see base example:
base example

from compress-images.

zgj233 avatar zgj233 commented on May 19, 2024

@semiromid thanks,According to what you said, I succeeded.

  1. InputPath must be written as the wildcard form like src/img/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}, couldn't I use a detail path like src/img/myDetailPath/one.png ?

  2. What happens when I use npm install ? You download real pngquant lib or other real 'compress image lib' something like jpegtran, mozjpeg, webp,svgo, imagemagick ···
    If you do, how exactly do you do it, can you teach me? please.

  3. When I run node compress-image.js command in your example project, img, png, gif were disposed successful. But throw error when dealing with SVG:

exec error : Error: Command failed: svgo --multipass -i src/img/my_post_images_1/NASA_logo.svg -o build/img/my_post_images_1/NASA_logo.svg
'svgo' is not recognized as an internal or external command,
operable program or batch file.

from compress-images.

Yuriy-Svetlov avatar Yuriy-Svetlov commented on May 19, 2024

I updated example, check new version.
https://github.com/semiromid/compress-images/tree/master/example
read the manual
https://github.com/semiromid/compress-images/blob/master/example/Manual.txt

Write please if you will be get error.

1 You could use detail path like src/img/myDetailPath/one.png

2 You download
https://github.com/imagemin/pngquant-bin ----> https://pngquant.org/
and other lib. You can see to
https://github.com/semiromid/compress-images ---- > "Related"
You do not need to use npm install - check new version example.

3.check new version example.

from compress-images.

Yuriy-Svetlov avatar Yuriy-Svetlov commented on May 19, 2024

Fix - https://github.com/semiromid/compress-images

from compress-images.

Related Issues (20)

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.