@@ -18,7 +18,11 @@ A simple NodeJS package for image compression powered by FFMPEG.
18
18
19
19
- ** Note:** The ** Mac OS** is currently not supported by this package as of the moment.
20
20
21
- - To check the FFMPEG latest build or release please refer to this link: [ FFMPEG Main Download Site] ( https://ffmpeg.org/download.html )
21
+ - To check the FFMPEG latest build or release please refer to this link: [ FFMPEG Main Download Link] ( https://ffmpeg.org/download.html )
22
+
23
+ - ImageMagick:
24
+
25
+ - To be able to use the "ProressiveJPEG" class this require the ImageMagick package. To get the latest version [ ImageMagick Download Link] ( https://imagemagick.org/script/download.php )
22
26
23
27
## Install
24
28
@@ -32,60 +36,132 @@ npm install nodejs-image-squeezer --save
32
36
33
37
## Usage
34
38
35
- - Below are the simple implementation of the package using ** TypeScript** :
39
+ ### FFMPEG
40
+
41
+ - Below are the simple implementation using ** TypeScript** :
42
+
43
+ ``` ts
44
+
45
+ // Import the main class of the NodeJS Image Squeezer.
46
+ import ImageSqueezer from ' nodejs-image-squeezer' ;
47
+
48
+ // Initialize the main class.
49
+ var imgSqueezer = new ImageSqueezer .FFMPEGComppresion ();
50
+
51
+ // Load the necessary requirements and validate
52
+ // if the package fit for the current environment.
53
+ imgSqueezer .load ();
54
+
55
+ // Override the default binaries ffmpeg.
56
+ imgSqueezer .setBin (' /path/to/binary' );
57
+
58
+ // Provide the source file path of the desire image
59
+ // that will be compress later on.
60
+ imgSqueezer .setSourceFilePath (' /path/source-filename' );
61
+
62
+ // Provide the output file path of the compressed image.
63
+ imgSqueezer .setOutputFilePath (' /path/output-filename' );
64
+
65
+ // (Optional) This will allow output file path as empty
66
+ // and will use the source file path as the output.
67
+ imgSqueezer .allowEmptyOutputFilePath ();
68
+
69
+ // Execute the image compression.
70
+ // return a promise.
71
+ imgSqueezer .compress ();
72
+ ```
73
+
74
+ - Basic implementation without using superset libraries for JavaScript (using a pure node.js syntax):
75
+
76
+ ``` js
77
+
78
+ // Require the main class of the NodeJS Image Squeezer.
79
+ var ImageSqueezer = require (' nodejs-image-squeezer' );
80
+
81
+ // Initialize the main class.
82
+ var imgSqueezer = new ImageSqueezer.FFMPEGComppresion ();
83
+
84
+ // Load the necessary requirements and validate
85
+ // if the package fit for the current environment.
86
+ imgSqueezer .load ();
87
+
88
+ // Override the default binaries ffmpeg.
89
+ imgSqueezer .setBin (' /path/to/binary' );
90
+
91
+ // Provide the source file path of the desire image
92
+ // that will be compress later on.
93
+ imgSqueezer .setSourceFilePath (' /path/source-filename' );
94
+
95
+ // Provide the output file path of the compressed image.
96
+ imgSqueezer .setOutputFilePath (' /path/output-filename' );
97
+
98
+ // (Optional) This will allow output file path as empty
99
+ // and will use the source file path as the output.
100
+ imgSqueezer .allowEmptyOutputFilePath ();
101
+
102
+ // Execute the image compression.
103
+ // return a promise.
104
+ imgSqueezer .compress ();
105
+ ```
106
+
107
+ ### JPEG Progressive
108
+
109
+ - Below are the simple implementation using ** TypeScript** :
36
110
37
111
``` ts
38
112
39
113
// Import the main class of the NodeJS Image Squeezer.
40
114
import ImageSqueezer from ' nodejs-image-squeezer' ;
41
115
42
116
// Initialize the main class.
43
- var imageSqueezer = new ImageSqueezer ();
117
+ var imgSqueezer = new ImageSqueezer . ProgressiveJPEG ();
44
118
45
119
// Load the necessary requirements and validate
46
120
// if the package fit for the current environment.
47
- imageSqueezer .load ();
121
+ imgSqueezer .load ();
48
122
49
- // Override the default binaries
50
- imageSqueezer . setFFMpegBin (' /path/to/binary' );
123
+ // Override the default binaries ffmpeg.
124
+ imgSqueezer . setBin (' /path/to/binary' );
51
125
52
126
// Provide the source file path of the desire image
53
127
// that will be compress later on.
54
- imageSqueezer .setSourceFilePath (' /path/source-filename' );
128
+ imgSqueezer .setSourceFilePath (' /path/source-filename' );
55
129
56
130
// Provide the output file path of the compressed image.
57
- imageSqueezer .setOutputFilePath (' /path/output-filename' );
131
+ imgSqueezer .setOutputFilePath (' /path/output-filename' );
58
132
59
133
// Execute the image compression.
60
- imageSqueezer .compress ();
134
+ // return a promise.
135
+ imgSqueezer .compress ();
61
136
```
62
137
63
- - Basic implementation of the package without superset libraries of JavaScript (using a pure node.js syntax):
138
+ - Basic implementation without using superset libraries for JavaScript (using a pure node.js syntax):
64
139
65
140
``` js
66
141
67
142
// Require the main class of the NodeJS Image Squeezer.
68
143
var ImageSqueezer = require (' nodejs-image-squeezer' );
69
144
70
145
// Initialize the main class.
71
- var imageSqueezer = new ImageSqueezer ();
146
+ var imgSqueezer = new ImageSqueezer.ProgressiveJPEG ();
72
147
73
148
// Load the necessary requirements and validate
74
149
// if the package fit for the current environment.
75
- imageSqueezer .load ();
150
+ imgSqueezer .load ();
76
151
77
- // Override the default binaries
78
- imageSqueezer . setFFMpegBin (' /path/to/binary' );
152
+ // Override the default binaries ffmpeg.
153
+ imgSqueezer . setBin (' /path/to/binary' );
79
154
80
155
// Provide the source file path of the desire image
81
156
// that will be compress later on.
82
- imageSqueezer .setSourceFilePath (' /path/source-filename' );
157
+ imgSqueezer .setSourceFilePath (' /path/source-filename' );
83
158
84
159
// Provide the output file path of the compressed image.
85
- imageSqueezer .setOutputFilePath (' /path/output-filename' );
160
+ imgSqueezer .setOutputFilePath (' /path/output-filename' );
86
161
87
162
// Execute the image compression.
88
- imageSqueezer .compress ();
163
+ // return a promise.
164
+ imgSqueezer .compress ();
89
165
```
90
166
91
167
## License
0 commit comments