jimp 0.2.27 → 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 +14 -0
- package/README.md +53 -10
- package/browser/.editorconfig +2 -0
- package/browser/README.md +2 -2
- package/browser/browserify-build.sh +2 -2
- package/browser/examples/dice.png +0 -0
- package/browser/examples/example1.html +3 -3
- package/browser/examples/jimp-worker.js +1 -1
- package/browser/examples/test.html +43 -0
- package/browser/lib/jimp.js +1 -3854
- package/browser/lib/jimp.min.js +2 -12
- package/index.js +372 -119
- package/jimp.d.ts +133 -0
- package/omggif.js +782 -0
- package/package.json +7 -4
- package/resize.js +120 -185
- package/resize2.js +15 -8
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,8 +42,6 @@ Jimp.read("lenna.png").then(function (lenna) {
|
|
|
34
42
|
});
|
|
35
43
|
```
|
|
36
44
|
|
|
37
|
-
Also available to use in web browsers and Electron applications. See [`browser/README.md`](https://github.com/oliver-moran/jimp/blob/master/browser/README.md).
|
|
38
|
-
|
|
39
45
|
## Basic usage ##
|
|
40
46
|
|
|
41
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:
|
|
@@ -80,21 +86,21 @@ image.scaleToFit( w, h[, mode] ); // scale the image to the largest size that fi
|
|
|
80
86
|
// An optional resize mode can be passed with all resize methods.
|
|
81
87
|
|
|
82
88
|
/* Crop */
|
|
83
|
-
image.autocrop();
|
|
89
|
+
image.autocrop([tolerance, frames]); // automatically crop same-color borders from image (if any), frames must be a Boolean
|
|
84
90
|
image.crop( x, y, w, h ); // crop to the given region
|
|
85
91
|
|
|
86
92
|
/* Composing */
|
|
87
93
|
image.blit( src, x, y[, srcx, srcy, srcw, srch] );
|
|
88
94
|
// blit the image with another Jimp image at x, y, optionally cropped.
|
|
89
95
|
image.composite( src, x, y ); // composites another Jimp image over this image at x, y
|
|
90
|
-
image.mask( src, x, y ); // masks the image with another Jimp image at x, y using average pixel value
|
|
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
|
|
91
98
|
|
|
92
99
|
/* Flip and rotate */
|
|
93
100
|
image.flip( horz, vert ); // flip the image horizontally or vertically
|
|
94
101
|
image.mirror( horz, vert ); // an alias for flip
|
|
95
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.
|
|
96
|
-
|
|
97
|
-
// 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.
|
|
98
104
|
|
|
99
105
|
/* Colour */
|
|
100
106
|
image.brightness( val ); // adjust the brighness by a value -1 to +1
|
|
@@ -108,7 +114,7 @@ image.normalize(); // normalize the channels in an image
|
|
|
108
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
|
|
109
115
|
image.opacity( f ); // multiply the alpha channel by each pixel by the factor f, 0 - 1
|
|
110
116
|
image.opaque(); // set the alpha channel on every pixel to fully opaque
|
|
111
|
-
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
|
|
112
118
|
|
|
113
119
|
/* Blurs */
|
|
114
120
|
image.gaussian( r ); // Gaussian blur the image by r pixels (VERY slow)
|
|
@@ -117,6 +123,10 @@ image.blur( r ); // fast blur the image by r pixels
|
|
|
117
123
|
/* Effects */
|
|
118
124
|
image.posterize( n ); // apply a posterization effect with n level
|
|
119
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.
|
|
120
130
|
```
|
|
121
131
|
|
|
122
132
|
Some of these methods are irreversable, so it can be useful to perform them on a clone of the original image:
|
|
@@ -129,7 +139,7 @@ image.clone(); // returns a clone of the image
|
|
|
129
139
|
|
|
130
140
|
### Resize modes ###
|
|
131
141
|
|
|
132
|
-
The default
|
|
142
|
+
The default resizing algorithm uses a bilinear method as follows:
|
|
133
143
|
|
|
134
144
|
```js
|
|
135
145
|
image.resize(250, 250); // resize the image to 250 x 250
|
|
@@ -228,6 +238,13 @@ The image can be written to disk in PNG, JPEG or BMP format (determined by the f
|
|
|
228
238
|
image.write( path, cb ); // Node-style callback will be fired when write is successful
|
|
229
239
|
```
|
|
230
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
|
+
|
|
231
248
|
### Writing to Buffers ###
|
|
232
249
|
|
|
233
250
|
A PNG, JPEG or BMP binary Buffer of an image (e.g. for storage in a database) can to got using:
|
|
@@ -244,7 +261,7 @@ Jimp.MIME_JPEG; // "image/jpeg"
|
|
|
244
261
|
Jimp.MIME_BMP; // "image/bmp"
|
|
245
262
|
```
|
|
246
263
|
|
|
247
|
-
If `Jimp.AUTO` is passed as the MIME type then the original MIME type for the image (or "image/png") will be used.
|
|
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").
|
|
248
265
|
|
|
249
266
|
### Data URI ###
|
|
250
267
|
|
|
@@ -316,6 +333,19 @@ Modifier | Description
|
|
|
316
333
|
**green** {amount} | Modify Green component by a given amount
|
|
317
334
|
**blue** {amount} | Modify Blue component by a given amount
|
|
318
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
|
+
|
|
319
349
|
### Low-level manipulation ###
|
|
320
350
|
|
|
321
351
|
Jimp enables low-level manipulation of images in memory through the bitmap property of each Jimp object:
|
|
@@ -331,7 +361,7 @@ This data can be manipulated directly but remember: garbage in, garbage out.
|
|
|
331
361
|
A helper method is available to scan a region of the bitmap:
|
|
332
362
|
|
|
333
363
|
```js
|
|
334
|
-
image.scan(x, y, w, h,
|
|
364
|
+
image.scan(x, y, w, h, f); // scan a given region of the bitmap and call the function f on every pixel
|
|
335
365
|
```
|
|
336
366
|
|
|
337
367
|
Example usage:
|
|
@@ -351,6 +381,19 @@ image.scan(0, 0, image.bitmap.width, image.bitmap.height, function (x, y, idx) {
|
|
|
351
381
|
// e.g. this.bitmap.data[idx] = 0; // removes red from this pixel
|
|
352
382
|
});
|
|
353
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
|
+
```
|
|
354
397
|
|
|
355
398
|
Alternatively, you can manipulate individual pixels using the following these functions:
|
|
356
399
|
|
package/browser/README.md
CHANGED
|
@@ -22,7 +22,7 @@ Jimp.read("lenna.png").then(function (lenna) {
|
|
|
22
22
|
</script>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
See the [main documentation](https://github.com/oliver-moran/jimp) for the
|
|
25
|
+
See the [main documentation](https://github.com/oliver-moran/jimp) for the full API documenatinon.
|
|
26
26
|
|
|
27
27
|
## WebWorkers ##
|
|
28
28
|
|
|
@@ -63,7 +63,7 @@ self.addEventListener("message", function(e) {
|
|
|
63
63
|
CDN access to the minified library is available through the [RawGit CDN](https://rawgit.com/):
|
|
64
64
|
|
|
65
65
|
```html
|
|
66
|
-
<script src="https://cdn.rawgit.com/oliver-moran/jimp/v0.2.
|
|
66
|
+
<script src="https://cdn.rawgit.com/oliver-moran/jimp/v0.2.28/browser/lib/jimp.min.js"></script>
|
|
67
67
|
```
|
|
68
68
|
|
|
69
69
|
## 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
|
|
8
|
+
echo "Browserifying index.js..."
|
|
9
9
|
ENVIRONMENT=BROWSER \
|
|
10
|
-
browserify --ignore-missing -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
|
|
|
Binary file
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<title>Jimp browser example 1</title>
|
|
5
5
|
</head>
|
|
6
6
|
<body>
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
<!-- Demonstrates loading a local file using Jimp on the main thread -->
|
|
9
9
|
<script src="../lib/jimp.min.js"></script>
|
|
10
10
|
<script>
|
|
@@ -19,6 +19,6 @@
|
|
|
19
19
|
});
|
|
20
20
|
});
|
|
21
21
|
</script>
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
</body>
|
|
24
|
-
</html>
|
|
24
|
+
</html>
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
|
|
12
|
+
function dropShadow(x, y, b, a) {
|
|
13
|
+
var img = new Jimp(this.bitmap.width + Math.abs(x*2) + (b*2), this.bitmap.height + Math.abs(y*2) + (b*2));
|
|
14
|
+
var orig = this.clone();
|
|
15
|
+
this.scan(0, 0, this.bitmap.width, this.bitmap.height, function (x, y, idx) {
|
|
16
|
+
this.bitmap.data[ idx + 0 ] = 0;
|
|
17
|
+
this.bitmap.data[ idx + 1 ] = 0;
|
|
18
|
+
this.bitmap.data[ idx + 2 ] = 0;
|
|
19
|
+
this.bitmap.data[ idx + 3 ] = this.bitmap.data[ idx + 3 ] * a;
|
|
20
|
+
});
|
|
21
|
+
// this.resize(this.bitmap.width + Math.abs(x) + b, this.bitmap.height + Math.abs(y) + b);
|
|
22
|
+
|
|
23
|
+
var x1 = Math.max(x * -1, 0) + b;
|
|
24
|
+
var y1 = Math.max(y * -1, 0) + b;
|
|
25
|
+
img.composite(this, x1, y1);
|
|
26
|
+
img.blur(b);
|
|
27
|
+
img.composite(orig, x1 - x, y1 - y);
|
|
28
|
+
//img.autocrop();
|
|
29
|
+
return img;
|
|
30
|
+
}
|
|
31
|
+
Jimp.read("dice.png").then(function (img) {
|
|
32
|
+
console.log(img.getMIME(), img.getExtension());
|
|
33
|
+
var img = dropShadow.call(img, 20, 20, 20, 0.3)
|
|
34
|
+
img.getBase64(Jimp.AUTO, function (err, src) {
|
|
35
|
+
var img = document.createElement("img");
|
|
36
|
+
img.setAttribute("src", src);
|
|
37
|
+
document.body.appendChild(img);
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
</script>
|
|
41
|
+
|
|
42
|
+
</body>
|
|
43
|
+
</html>
|