jimp 0.2.24 → 0.2.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.editorconfig ADDED
@@ -0,0 +1,14 @@
1
+ # See http://editorconfig.org/ for valid options and editor plugins.
2
+
3
+ # Prevents EditorConfig from searching higher in the tree
4
+ root = true
5
+
6
+ [*]
7
+ indent_style = space
8
+ indent_size = 4
9
+ end_of_line = lf
10
+ trim_trailing_whitespace = false
11
+ insert_final_newline = true
12
+
13
+ [package.json]
14
+ indent_size = 2
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
+ <hr>
2
+
3
+ **Can you help maintain this project?**
4
+
5
+ Collaborators wanted: https://github.com/oliver-moran/jimp/issues/219
6
+
7
+ <hr>
8
+
1
9
  # Jimp #
2
10
 
3
11
  The "JavaScript Image Manipulation Program" :-)
@@ -34,9 +42,6 @@ Jimp.read("lenna.png").then(function (lenna) {
34
42
  });
35
43
  ```
36
44
 
37
- Now also available for use in the browser for image manipulation in web workers without `<canvas>`. See [`browser/README.md`](https://github.com/oliver-moran/jimp/blob/master/browser/README.md).
38
-
39
-
40
45
  ## Basic usage ##
41
46
 
42
47
  The static `Jimp.read` method takes the path to a PNG, JPEG or BMP file and (optionally) a Node-style callback and returns a Promise:
@@ -72,8 +77,8 @@ Once the callback is filed or the promise fulfilled, the following methods can b
72
77
 
73
78
  ```js
74
79
  /* Resize */
75
- image.contain( w, h[, mode] ); // scale the image to the given width and height, some parts of the image may be letter boxed
76
- image.cover( w, h[, mode] ); // scale the image to the given width and height, some parts of the image may be clipped
80
+ image.contain( w, h[, alignBits || mode, mode] ); // scale the image to the given width and height, some parts of the image may be letter boxed
81
+ image.cover( w, h[, alignBits || mode, mode] ); // scale the image to the given width and height, some parts of the image may be clipped
77
82
  image.resize( w, h[, mode] ); // resize the image. Jimp.AUTO can be passed as one of the values.
78
83
  image.scale( f[, mode] ); // scale the image by the factor f
79
84
  image.scaleToFit( w, h[, mode] ); // scale the image to the largest size that fits inside the given width and height
@@ -81,21 +86,21 @@ image.scaleToFit( w, h[, mode] ); // scale the image to the largest size that fi
81
86
  // An optional resize mode can be passed with all resize methods.
82
87
 
83
88
  /* Crop */
84
- image.autocrop(); // automatically crop same-color borders from image (if any)
89
+ image.autocrop([tolerance, frames]); // automatically crop same-color borders from image (if any), frames must be a Boolean
85
90
  image.crop( x, y, w, h ); // crop to the given region
86
91
 
87
92
  /* Composing */
88
93
  image.blit( src, x, y[, srcx, srcy, srcw, srch] );
89
94
  // blit the image with another Jimp image at x, y, optionally cropped.
90
- image.composite( src, x, y ); // composites another Jimp image over this iamge at x, y
91
- image.mask( src, x, y ); // masks the image with another Jimp image at x, y using average pixel value image.rotate) and when writing formats that don't support alpha channels
95
+ image.composite( src, x, y ); // composites another Jimp image over this image at x, y
96
+ image.mask( src, x, y ); // masks the image with another Jimp image at x, y using average pixel value
97
+ image.convolute( kernel ); // applies a convolution kernel matrix to the image or a region
92
98
 
93
99
  /* Flip and rotate */
94
100
  image.flip( horz, vert ); // flip the image horizontally or vertically
95
101
  image.mirror( horz, vert ); // an alias for flip
96
102
  image.rotate( deg[, mode] ); // rotate the image clockwise by a number of degrees. Optionally, a resize mode can be passed. If `false` is passed as the second parameter, the image width and height will not be resized.
97
-
98
- // JPEG images with EXIF orientation data will be automatically re-orientated as appropriate.
103
+ image.exifRotate(); // JPEG images with EXIF orientation data will be automatically re-orientated as appropriate.
99
104
 
100
105
  /* Colour */
101
106
  image.brightness( val ); // adjust the brighness by a value -1 to +1
@@ -109,7 +114,7 @@ image.normalize(); // normalize the channels in an image
109
114
  image.fade( f ); // an alternative to opacity, fades the image by a factor 0 - 1. 0 will haven no effect. 1 will turn the image
110
115
  image.opacity( f ); // multiply the alpha channel by each pixel by the factor f, 0 - 1
111
116
  image.opaque(); // set the alpha channel on every pixel to fully opaque
112
- image.background( hex ); // set the default new pixel colour (e.g. 0xFFFFFFFF or 0x00000000) for by some operations (e.g. image.contain and
117
+ image.background( hex ); // set the default new pixel colour (e.g. 0xFFFFFFFF or 0x00000000) for by some operations (e.g. image.contain and
113
118
 
114
119
  /* Blurs */
115
120
  image.gaussian( r ); // Gaussian blur the image by r pixels (VERY slow)
@@ -118,6 +123,10 @@ image.blur( r ); // fast blur the image by r pixels
118
123
  /* Effects */
119
124
  image.posterize( n ); // apply a posterization effect with n level
120
125
  image.sepia(); // apply a sepia wash to the image
126
+ image.pixelate( size[, x, y, w, h ]); // apply a pixelation effect to the image or a region
127
+
128
+ /* 3D */
129
+ image.displace( map, offset ); // displaces the image pixels based on the provided displacement map. Useful for making stereoscopic 3D images.
121
130
  ```
122
131
 
123
132
  Some of these methods are irreversable, so it can be useful to perform them on a clone of the original image:
@@ -130,7 +139,7 @@ image.clone(); // returns a clone of the image
130
139
 
131
140
  ### Resize modes ###
132
141
 
133
- The default rezing algorithm uses a bilinear method as follows:
142
+ The default resizing algorithm uses a bilinear method as follows:
134
143
 
135
144
  ```js
136
145
  image.resize(250, 250); // resize the image to 250 x 250
@@ -154,13 +163,40 @@ For example:
154
163
  image.resize(250, 250, Jimp.RESIZE_BEZIER);
155
164
  ```
156
165
 
166
+ ### Align modes ###
167
+
168
+ The following constants can be passed to image.cover and image.contain methods:
169
+
170
+ ```js
171
+ Jimp.HORIZONTAL_ALIGN_LEFT;
172
+ Jimp.HORIZONTAL_ALIGN_CENTER;
173
+ Jimp.HORIZONTAL_ALIGN_RIGHT;
174
+
175
+ Jimp.VERTICAL_ALIGN_TOP;
176
+ Jimp.VERTICAL_ALIGN_MIDDLE;
177
+ Jimp.VERTICAL_ALIGN_BOTTOM;
178
+ ```
179
+
180
+ For example:
181
+
182
+ ```js
183
+ image.contain(250, 250, Jimp.HORIZONTAL_ALIGN_LEFT | Jimp.VERTICAL_ALIGN_TOP);
184
+ ```
185
+
186
+ Default align modes are :
187
+
188
+ ```js
189
+ Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE;
190
+ ```
191
+
157
192
  ### Writing text ###
158
193
 
159
194
  Jimp supports basic typography using BMFont format (.fnt) [bitmap fonts](https://en.wikipedia.org/wiki/Bitmap_fonts):
160
195
 
161
196
  ```js
162
197
  Jimp.loadFont( path ).then(function (font) { // load font from .fnt file
163
- image.print(font, x, y, str); // print a message on an image
198
+ image.print(font, x, y, str); // print a message on an image
199
+ image.print(font, x, y, str, width); // print a message on an image with text wrapped at width
164
200
  });
165
201
 
166
202
  Jimp.loadFont( path, cb ); // using a callback pattern
@@ -202,12 +238,19 @@ The image can be written to disk in PNG, JPEG or BMP format (determined by the f
202
238
  image.write( path, cb ); // Node-style callback will be fired when write is successful
203
239
  ```
204
240
 
241
+ The original extension for an image (or "png") can accessed as using `image.getExtension()`. The following will save an image using its original format:
242
+
243
+ ```js
244
+ var file = "new_name." + image.getExtension();
245
+ image.write(file)
246
+ ```
247
+
205
248
  ### Writing to Buffers ###
206
249
 
207
250
  A PNG, JPEG or BMP binary Buffer of an image (e.g. for storage in a database) can to got using:
208
251
 
209
252
  ```js
210
- image.getBuffer( mime, cb ); // Node-style callback wil be fired with result
253
+ image.getBuffer( mime, cb ); // Node-style callback will be fired with result
211
254
  ```
212
255
 
213
256
  For convenience, supported MIME types are available as static properties:
@@ -218,6 +261,16 @@ Jimp.MIME_JPEG; // "image/jpeg"
218
261
  Jimp.MIME_BMP; // "image/bmp"
219
262
  ```
220
263
 
264
+ If `Jimp.AUTO` is passed as the MIME type then the original MIME type for the image (or "image/png") will be used. Alernatively, `image.getMIME()` will return the original MIME type of the image (or "image/png").
265
+
266
+ ### Data URI ###
267
+
268
+ A Base64 data URI can be generated in the same way as a Buffer, using:
269
+
270
+ ```js
271
+ image.getBase64( mime, cb ); // Node-style callback will be fired with result
272
+ ```
273
+
221
274
  ### PNG and JPEG quality ###
222
275
 
223
276
  The quality of JPEGs can be set with:
@@ -229,9 +282,10 @@ image.quality( n ); // set the quality of saved JPEG, 0 - 100
229
282
  The format of PNGs can be set with:
230
283
 
231
284
  ```js
232
- image.rgba( bool ); // set whether PNGs are saved as RGBA (true, default) or RGB (false)
233
- image.filterType( number ); // set the filter type for the saved PNG
234
- image.deflateLevel( number ); // set the deflate level for the saved PNG
285
+ image.rgba( bool ); // set whether PNGs are saved as RGBA (true, default) or RGB (false)
286
+ image.filterType( number ); // set the filter type for the saved PNG
287
+ image.deflateLevel( number ); // set the deflate level for the saved PNG
288
+ Jimp.deflateStrategy( number ); // set the deflate for the saved PNG (0-3)
235
289
  ```
236
290
 
237
291
  For convenience, supported filter types are available as static properties:
@@ -279,6 +333,19 @@ Modifier | Description
279
333
  **green** {amount} | Modify Green component by a given amount
280
334
  **blue** {amount} | Modify Blue component by a given amount
281
335
 
336
+ ### Convolution matrix ###
337
+
338
+ Sum neighbor pixels weighted by the kernel matrix. You can find a nice explanation with examples at [GIMP's Convolution Matrix plugin](https://docs.gimp.org/en/plug-in-convmatrix.html)
339
+
340
+ Implement emboss effect:
341
+ ```js
342
+ image.convolution([
343
+ [-2,-1, 0],
344
+ [-1, 1, 1],
345
+ [ 0, 1, 2]
346
+ ])
347
+ ```
348
+
282
349
  ### Low-level manipulation ###
283
350
 
284
351
  Jimp enables low-level manipulation of images in memory through the bitmap property of each Jimp object:
@@ -294,7 +361,7 @@ This data can be manipulated directly but remember: garbage in, garbage out.
294
361
  A helper method is available to scan a region of the bitmap:
295
362
 
296
363
  ```js
297
- image.scan(x, y, w, h, cb); // scan a given region of the bitmap and call cb on every pixel
364
+ image.scan(x, y, w, h, f); // scan a given region of the bitmap and call the function f on every pixel
298
365
  ```
299
366
 
300
367
  Example usage:
@@ -314,6 +381,19 @@ image.scan(0, 0, image.bitmap.width, image.bitmap.height, function (x, y, idx) {
314
381
  // e.g. this.bitmap.data[idx] = 0; // removes red from this pixel
315
382
  });
316
383
  ```
384
+ A helper to locate a particular pixel within the raw bitmap buffer:
385
+
386
+ ```js
387
+ image.getPixelIndex(x, y); // returns the index within image.bitmap.data
388
+ ```
389
+
390
+ One of the following may be optionally passed as a third parameter to indicate a strategy for x, y positions that are outside of boundaries of the image:
391
+
392
+ ```js
393
+ Jimp.EDGE_EXTEND = 1;
394
+ Jimp.EDGE_WRAP = 2;
395
+ Jimp.EDGE_CROP = 3;
396
+ ```
317
397
 
318
398
  Alternatively, you can manipulate individual pixels using the following these functions:
319
399
 
@@ -0,0 +1,2 @@
1
+ # Exclude this directory
2
+ root = true
package/browser/README.md CHANGED
@@ -1,229 +1,71 @@
1
- # Jimp ... for Web Workers #
1
+ # Jimp ... in a browser #
2
2
 
3
- The "JavaScript Image Manipulation Program" ... for Web Workers! :-)
3
+ Browser support for Jimp was added by Phil Seaton. This enabled Jimp to be used in [Electron](http://electron.atom.io/) applications as well as web browsers.
4
4
 
5
- A fork of the wonderful Jimp by oliver-moran (https://github.com/oliver-moran/jimp). Jimp runs in node, Jimp for the browser runs in a Web Worker.
6
-
7
- This version of the library lets you do fully multi-threaded image manipulation in a browser context without using ```<canvas>```. Its API is essentially the same as Jimp's, so be sure to browse the documentation there. It's generally compatible with Firefox 11+, Chrome, Safari 6+, and IE 11+. It is compatible with BMP, JPG, and PNG files (as is Jimp). The full-featured version, which does everything Jimp does, is 90kb gzipped. Much smaller versions can be built easily by excluding features and dependencies from the library. See index.js.
8
-
9
- ## Demo ##
10
-
11
- Head over to http://strandedcity.github.io/jimp/browser/
12
-
13
- Select images, or just click to use images from the /test directory. Your images will be loaded by the browser, and each will be thumbailed and greyscaled, two of Jimp's simplest and most useful operations. Each image will be correctly oriented according to its exif data and displayed in two ways, with different implications for web applications:
14
-
15
- ```js
16
- var canvas = document.createElement("canvas");
17
- canvas.width = image.width;
18
- canvas.height = image.height;
19
- document.body.appendChild(canvas);
20
-
21
- var ctx = canvas.getContext("2d");
22
- var imgData = ctx.createImageData(image.width,image.height);
23
-
24
- ...
25
-
26
- ctx.putImageData(imgData,0,0);
27
- ```
28
-
29
- and
5
+ Example usage:
30
6
 
31
7
  ```html
32
- <img src="[data URI]" width="xx" height="xx" />
33
- ```
34
-
35
- ## Basic Usage: Input ##
36
-
37
- As much work as possible should be done on the worker thread, but since Web Workers cannot interact with the DOM there are some divisions of labor that must take place.
38
-
39
- These files are meant to be customized for your your use:
40
- - jimp-worker.js
41
- - index.html
42
-
43
- Generally, you should expect to create the worker in index.html:
44
- ```js
45
- var worker = new Worker("jimp-worker.js");
46
- ```
47
- and send it data in one of these ways:
48
-
49
- ##### Input Type 1: Send url to be read in worker via xhr: #####
50
- ```js
51
- worker.postMessage("/some/local/path/to/image.jpg");
52
- ```
53
-
54
- ##### Input Type 2: Pass an ArrayBuffer to be read in directly: #####
55
- ```js
56
- var element = document.getElementById("fileSelectionElement"),
57
- file = element.files[0],
58
- fr = new FileReader();
59
-
60
- fr.addEventListener("load",function(){
61
- worker.postMessage(this.result);
8
+ <script src="jimp.min.js"></script>
9
+ <script>
10
+ Jimp.read("lenna.png").then(function (lenna) {
11
+ lenna.resize(256, 256) // resize
12
+ .quality(60) // set JPEG quality
13
+ .greyscale() // set greyscale
14
+ .getBase64(Jimp.MIME_JPEG, function (err, src) {
15
+ var img = document.createElement("img");
16
+ img.setAttribute("src", src);
17
+ document.body.appendChild(img);
18
+ });
19
+ }).catch(function (err) {
20
+ console.error(err);
62
21
  });
63
- fr.readAsArrayBuffer(readfile);
22
+ </script>
64
23
  ```
65
24
 
66
- Demo code in jimp-worker.js will take care of reading the image data such that a Jimp object can be created.
25
+ See the [main documentation](https://github.com/oliver-moran/jimp) for the full API documenatinon.
67
26
 
68
- ## Basic Usage: Output ##
27
+ ## WebWorkers ##
69
28
 
70
- In a node.js context, Jimp writes to files. In a browser context, this is less useful. Follow the example to see how to retrieve your processed images from jimp-worker.js once they are available. In a nutshell, you'll receive post messages back from the worker with two types of data that are easy to display in the browser, upload, etc:
29
+ For better performance, it recommended that Jimp methods are run on a separate thread using [`WebWorkers`](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers). The following shows how using two files (`index.html` and `jimp-worker.js`):
71
30
 
72
- ##### Output Type 1: As an Image Object for display on ```<canvas>```:#####
73
31
  ```js
74
- worker.onmessage = function(e){
75
- var returnObject = e.data;
76
-
77
- if (returnObject.type === "IMAGE") {
78
- // display the processed image by drawing in a canvas:
79
- var image = returnObject.data;
80
- var canvas = document.createElement("canvas");
81
- canvas.width = image.width;
82
- canvas.height = image.height;
83
- document.body.appendChild(canvas);
84
-
85
- var ctx = canvas.getContext("2d");
86
- var imgData = ctx.createImageData(image.width,image.height);
87
-
88
- var ubuf = image.data;
89
- for (var i=0;i < ubuf.length; i+=4) {
90
- imgData.data[i] = ubuf[i]; //red
91
- imgData.data[i+1] = ubuf[i+1]; //green
92
- imgData.data[i+2] = ubuf[i+2]; //blue
93
- imgData.data[i+3] = ubuf[i+3]; //alpha
94
- }
95
-
96
- ctx.putImageData(imgData,0,0);
97
- }
98
- };
99
- ```
32
+ // index.html
100
33
 
101
- ##### Output Type 2: As a Data URI for display in ```<img>```:#####
102
- ```js
103
- worker.onmessage = function(e){
104
- var returnObject = e.data;
105
-
106
- if (returnObject.type === "DATA_URI") {
107
- // display processed image by data URI:
108
- var dataUri = returnObject.data;
109
- var width = returnObject.width;
110
- var height = returnObject.height;
111
-
112
- var image = document.createElement("img");
113
- image.src = dataUri;
114
- image.width = w;
115
- image.height = h;
116
- document.body.appendChild(image);
117
- }
34
+ var worker = new Worker("jimp-worker.js");
35
+ worker.onmessage = function (e) {
36
+ // append a new img element using the base 64 image
37
+ var img = document.createElement("img");
38
+ img.setAttribute("src", e.data);
39
+ document.body.appendChild(img);
118
40
  };
41
+ worker.postMessage("lenna.png"); // message the worker thread
119
42
  ```
120
43
 
121
- ## Image Manipulation ##
122
-
123
- In jimp-worker.js, syntax for Jimp works the same as it does in node (see https://github.com/oliver-moran/jimp). Inside self.onmessage:
124
44
  ```js
125
- Jimp.read(e.data).then(function(image){
126
- image.containCropped(200, 200) // fit the image in a 200px square
127
- .greyscale() // make it B&W
128
- .quality(60); // set JPEG quality (only applies to jpegs)
129
-
130
- // Return resized image data to the main thread:
131
- self.postMessage({
132
- type: "IMAGE",
133
- data: image.bitmap,
134
- width: image.bitmap.width,
135
- height: image.bitmap.height
136
- });
45
+ // jimp-worker.js
46
+
47
+ importScripts("jimp.min.js");
48
+
49
+ self.addEventListener("message", function(e) {
50
+ Jimp.read(e.data).then(function (lenna) {
51
+ lenna.resize(256, 256) // resize
52
+ .quality(60) // set JPEG quality
53
+ .greyscale() // set greyscale
54
+ .getBase64(Jimp.MIME_JPEG, function (err, src) {
55
+ self.postMessage(src); // message the main thread
56
+ });
137
57
  });
58
+ });
138
59
  ```
139
60
 
140
- JPEG images with EXIF orientation data will be automatically re-orientated as appropriate.
141
-
142
- The following methods can be called on the image:
143
-
144
- ```js
145
- image.crop( x, y, w, h ); // crop to the given region
146
- image.autocrop(); // automatically crop same-color borders from image (if any)
147
- image.invert(); // invert the image colours
148
- image.flip( horz, vert ); // flip the image horizontally or vertically
149
- image.gaussian( r ); // Gaussian blur the image by r pixels (VERY slow)
150
- image.blur( r ); // fast blur the image by r pixels
151
- image.greyscale(); // remove colour from the image
152
- image.sepia(); // apply a sepia wash to the image
153
- image.opacity( f ); // multiply the alpha channel by each pixel by the factor f, 0 - 1
154
- image.resize( w, h ); // resize the image. Jimp.AUTO can be passed as one of the values.
155
- image.scale( f ); // scale the image by the factor f
156
- image.rotate( deg[, resize] ); // rotate the image clockwise by a number of degrees. Unless `false` is passed as the second parameter, the image width and height will be resized appropriately.
157
- image.blit( src, x, y ); // blit the image with another Jimp image at x, y
158
- image.composite( src, x, y ); // composites another Jimp image over this iamge at x, y
159
- image.brightness( val ); // adjust the brighness by a value -1 to +1
160
- image.contrast( val ); // adjust the contrast by a value -1 to +1
161
- image.posterize( n ); // apply a posterization effect with n level
162
- image.mask( src, x, y ); // masks the image with another Jimp image at x, y using average pixel value
163
- image.dither565(); // ordered dithering of the image and reduce color space to 16-bits (RGB565)
164
- image.cover( w, h ); // scale the image so that it fills the given width and height
165
- image.contain( w, h ); // scale the image to the largest size so that fits inside the given width and height
166
- image.containCropped( w, h ); // same as .contain(), but returns an image without "blank" pixels filled with a background color
167
- image.background( hex ); // set the default new pixel colour (e.g. 0xFFFFFFFF or 0x00000000) for by some operations (e.g. image.contain and image.rotate) and when writing formats that don't support alpha channels
168
- image.mirror( horz, vert ); // an alias for flip
169
- image.fade( f ); // an alternative to opacity, fades the image by a factor 0 - 1. 0 will haven no effect. 1 will turn the image
170
- image.opaque(); // set the alpha channel on every pixel to fully opaque
171
- image.clone(); // returns a clone of the image
172
- ```
173
-
174
- (Contributions of more methods are welcome!)
175
-
176
- ### PNG and JPEG quality ###
177
-
178
- The quality of JPEGs can be set with:
179
-
180
- ```js
181
- image.quality( n ); // set the quality of saved JPEG, 0 - 100
182
- ```
183
-
184
- The format of PNGs can be set with:
185
-
186
- ```js
187
- image.rgba( bool ); // set whether PNGs are saved as RGBA (true, default) or RGB (false)
188
- image.filterType( number ); // set the filter type for the saved PNG
189
- image.deflateLevel( number ); // set the deflate level for the saved PNG
190
- ```
191
-
192
- For convenience, supported filter types are available as static properties:
193
-
194
- ```js
195
- Jimp.PNG_FILTER_AUTO; // -1
196
- Jimp.PNG_FILTER_NONE; // 0
197
- Jimp.PNG_FILTER_SUB; // 1
198
- Jimp.PNG_FILTER_UP; // 2
199
- Jimp.PNG_FILTER_AVERAGE; // 3
200
- Jimp.PNG_FILTER_PAETH; // 4
201
- ```
202
-
203
- ## Compiling jimp.js and jimp.min.js ##
61
+ ## CDN ##
204
62
 
205
- Clone the repo and run ```$ npm install``
63
+ CDN access to the minified library is available through the [RawGit CDN](https://rawgit.com/):
206
64
 
207
- To rebuild the minified JavaScript files jimp.js and jimp.min.js, run ```$ npm run prepublish``` at any time.
208
-
209
- ```
210
- $ npm install
211
-
212
- > jimp@0.2.20 prepublish /home/<location>/jimp
213
- > ./browser/browserify-build.sh
214
-
215
- Browserifying browser/jimp.js...
216
- Translating for ES5...
217
- Removing Strict Mode.
218
- Adding Web Worker wrapper functions...
219
- Minifying browser/jimp.min.js...
220
- Cleaning up....
65
+ ```html
66
+ <script src="https://cdn.rawgit.com/oliver-moran/jimp/v0.2.28/browser/lib/jimp.min.js"></script>
221
67
  ```
222
68
 
223
- ## Advanced usage ##
224
-
225
- See the origin fork at https://github.com/oliver-moran/jimp for full documentation of Jimp.
226
-
227
69
  ## License ##
228
70
 
229
71
  Jimp is licensed under the MIT license.
@@ -5,9 +5,9 @@
5
5
  # eg: I/O, Affine Transforms, Bitmap Operations, Gamma Curves, and Layers
6
6
  # Initial Build includes everything except file IO, which is browser-incompatible
7
7
  cd ${0%/*}
8
- echo "Browserifying browser/jimp.js..."
8
+ echo "Browserifying index.js..."
9
9
  ENVIRONMENT=BROWSER \
10
- browserify -t envify -t uglifyify ../index.js > tmp1.js
10
+ browserify --ignore-missing Buffer -t envify -t uglifyify ../index.js > tmp1.js
11
11
  echo "Translating for ES5..."
12
12
  babel tmp1.js -o tmp.js --presets es2015,stage-0
13
13
 
@@ -27,7 +27,7 @@ npm run-script minify-jimp
27
27
 
28
28
 
29
29
  echo "Including the License and version number in the jimp.js and jimp.min.js"
30
- PACKAGE_VERSION=$(cat ../package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[",]//g')
30
+ PACKAGE_VERSION=$(cat ../package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[", ]//g')
31
31
  { echo "/*";
32
32
  echo "Jimp v$PACKAGE_VERSION";
33
33
  echo "https://github.com/oliver-moran/jimp";
@@ -40,5 +40,8 @@ echo ""; } > tmp.web_license.txt
40
40
  (cat tmp.web_license.txt ; echo "var window = window || self;" ; cat tmp.jimp.js; ) > lib/jimp.js
41
41
  (cat tmp.web_license.txt ; echo "var window = window || self;" ; cat tmp.jimp.min.js; ) > lib/jimp.min.js
42
42
 
43
+ echo "Updating package version in README.md"
44
+ sed -i.bak "s/v[0-9][0-9]*.[0-9][0-9]*.[0-9][0-9]*/v$PACKAGE_VERSION/g" README.md; rm README.md.bak
45
+
43
46
  echo "Cleaning up...."
44
47
  rm tmp*
Binary file
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Jimp browser example 1</title>
5
+ </head>
6
+ <body>
7
+
8
+ <!-- Demonstrates loading a local file using Jimp on the main thread -->
9
+ <script src="../lib/jimp.min.js"></script>
10
+ <script>
11
+ Jimp.read("https://upload.wikimedia.org/wikipedia/commons/0/01/Bot-Test.jpg").then(function (lenna) {
12
+ lenna.resize(256, Jimp.AUTO) // resize
13
+ .quality(60) // set JPEG quality
14
+ .greyscale() // set greyscale
15
+ .getBase64(Jimp.AUTO, function (err, src) {
16
+ var img = document.createElement("img");
17
+ img.setAttribute("src", src);
18
+ document.body.appendChild(img);
19
+ });
20
+ });
21
+ </script>
22
+
23
+ </body>
24
+ </html>
@@ -0,0 +1,20 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Jimp browser example 2</title>
5
+ </head>
6
+ <body>
7
+
8
+ <!-- Demonstrates loading a relative file using Jimp on a WebWorker thread -->
9
+ <script>
10
+ var worker = new Worker("jimp-worker.js");
11
+ worker.onmessage = function (e) {
12
+ var img = document.createElement("img");
13
+ img.setAttribute("src", e.data);
14
+ document.body.appendChild(img);
15
+ };
16
+ worker.postMessage("lenna.png");
17
+ </script>
18
+
19
+ </body>
20
+ </html>
@@ -0,0 +1,35 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Jimp browser example 3</title>
5
+ </head>
6
+ <body>
7
+
8
+ <!-- Demonstrates loading a local file using Jimp on a WebWorker thread -->
9
+ <p><input type="file" onchange="newFiles(this);" /></p>
10
+ <script>
11
+
12
+ function newFiles(element){
13
+ for (var i=0; i<element.files.length; i++) {
14
+ readFileAndProcess(element.files[i]);
15
+ }
16
+
17
+ function readFileAndProcess(readfile){
18
+ var reader = new FileReader();
19
+ reader.addEventListener("load", function(){
20
+ var worker = new Worker("jimp-worker.js");
21
+ worker.onmessage = function (e) {
22
+ var img = document.createElement("img");
23
+ img.setAttribute("src", e.data);
24
+ document.body.appendChild(img);
25
+ };
26
+ worker.postMessage(this.result);
27
+ });
28
+ reader.readAsArrayBuffer(readfile);
29
+ }
30
+ }
31
+
32
+ </script>
33
+
34
+ </body>
35
+ </html>
@@ -0,0 +1,13 @@
1
+ importScripts("../lib/jimp.min.js");
2
+
3
+ self.addEventListener("message", function(e) {
4
+ Jimp.read(e.data).then(function (lenna) {
5
+ lenna.resize(256, Jimp.AUTO) // resize
6
+ .quality(60) // set JPEG quality
7
+ .greyscale() // set greyscale
8
+ .getBase64(Jimp.AUTO, function (err, src) {
9
+ self.postMessage(src);
10
+ self.close();
11
+ });
12
+ });
13
+ });
Binary file