Comments (5)
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.
You can to see base example:
base example
from compress-images.
@semiromid thanks,According to what you said, I succeeded.
-
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 likesrc/img/myDetailPath/one.png
? -
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. -
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.
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.
Fix - https://github.com/semiromid/compress-images
from compress-images.
Related Issues (20)
- images are not saved to exact paths HOT 12
- Suggestions to avoid passing excessive arguments and use well-constructed options HOT 1
- GIF-LIB error: Image EOF detected before image complete. HOT 4
- Support to Typescript HOT 5
- Get an error during installing module HOT 3
- Exclude folder HOT 1
- Error of inputting path HOT 1
- Does it protect itself from zip bombs ? HOT 2
- Is it possible to resize ? HOT 3
- Update Dependencies HOT 4
- file does not exist when it does? HOT 1
- Why the finally file size has increased? HOT 2
- tell me to install a additional module HOT 6
- Compatibility with pngquant-bin v7 HOT 5
- Unrecognized option: 'u' HOT 1
- why gif become blurry after run "compress_images.js" HOT 1
- Ability to input the file instead of its path HOT 1
- error Error [TypeError]: Cannot read properties of undefined (reading 'engine')
- Outdated dependency update?
- How do I disable logging and statistics? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compress-images.