chore: add jimp dependency, icon padding script, and update configuration
This commit is contained in:
+67
@@ -0,0 +1,67 @@
|
||||
# Jimp ... in a browser
|
||||
|
||||
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.
|
||||
|
||||
Example usage:
|
||||
|
||||
```html
|
||||
<script src="jimp.min.js"></script>
|
||||
<script>
|
||||
Jimp.read("lenna.png")
|
||||
.then(function (lenna) {
|
||||
lenna
|
||||
.resize(256, 256) // resize
|
||||
.quality(60) // set JPEG quality
|
||||
.greyscale() // set greyscale
|
||||
.getBase64(Jimp.MIME_JPEG, function (err, src) {
|
||||
var img = document.createElement("img");
|
||||
img.setAttribute("src", src);
|
||||
document.body.appendChild(img);
|
||||
});
|
||||
})
|
||||
.catch(function (err) {
|
||||
console.error(err);
|
||||
});
|
||||
</script>
|
||||
```
|
||||
|
||||
See the [main documentation](https://github.com/jimp-dev/jimp) for the full API documenatinon.
|
||||
|
||||
## WebWorkers
|
||||
|
||||
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`):
|
||||
|
||||
```js
|
||||
// index.html
|
||||
|
||||
var worker = new Worker("jimp-worker.js");
|
||||
worker.onmessage = function (e) {
|
||||
// append a new img element using the base 64 image
|
||||
var img = document.createElement("img");
|
||||
img.setAttribute("src", e.data);
|
||||
document.body.appendChild(img);
|
||||
};
|
||||
worker.postMessage("lenna.png"); // message the worker thread
|
||||
```
|
||||
|
||||
```js
|
||||
// jimp-worker.js
|
||||
|
||||
importScripts("jimp.min.js");
|
||||
|
||||
self.addEventListener("message", function (e) {
|
||||
Jimp.read(e.data).then(function (lenna) {
|
||||
lenna
|
||||
.resize(256, 256) // resize
|
||||
.quality(60) // set JPEG quality
|
||||
.greyscale() // set greyscale
|
||||
.getBase64(Jimp.MIME_JPEG, function (err, src) {
|
||||
self.postMessage(src); // message the main thread
|
||||
});
|
||||
});
|
||||
});
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Jimp is licensed under the MIT license.
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 213 KiB |
+25
@@ -0,0 +1,25 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Jimp browser example 1</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Demonstrates loading a local file using Jimp on the main thread</h1>
|
||||
<script src="../lib/jimp.js"></script>
|
||||
<script>
|
||||
Jimp.read(
|
||||
"https://upload.wikimedia.org/wikipedia/commons/0/01/Bot-Test.jpg"
|
||||
).then(function (lenna) {
|
||||
lenna
|
||||
.resize(256, Jimp.AUTO) // resize
|
||||
.quality(60) // set JPEG quality
|
||||
.greyscale() // set greyscale
|
||||
.getBase64(Jimp.AUTO, function (err, src) {
|
||||
var img = document.createElement("img");
|
||||
img.setAttribute("src", src);
|
||||
document.body.appendChild(img);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Jimp browser example 2</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>
|
||||
Demonstrates loading a relative file using Jimp on a WebWorker thread
|
||||
</h1>
|
||||
<script>
|
||||
var worker = new Worker("jimp-worker.js");
|
||||
worker.onmessage = function (e) {
|
||||
var img = document.createElement("img");
|
||||
img.setAttribute("src", e.data);
|
||||
document.body.appendChild(img);
|
||||
};
|
||||
worker.postMessage("lenna.png");
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Jimp browser example 3</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Demonstrates loading a local file using Jimp on a WebWorker thread</h1>
|
||||
<p><input type="file" onchange="newFiles(this);" /></p>
|
||||
<script>
|
||||
function newFiles(element) {
|
||||
for (var i = 0; i < element.files.length; i++) {
|
||||
readFileAndProcess(element.files[i]);
|
||||
}
|
||||
|
||||
function readFileAndProcess(readfile) {
|
||||
var reader = new FileReader();
|
||||
reader.addEventListener("load", function () {
|
||||
var worker = new Worker("jimp-worker.js");
|
||||
worker.onmessage = function (e) {
|
||||
var img = document.createElement("img");
|
||||
img.setAttribute("src", e.data);
|
||||
document.body.appendChild(img);
|
||||
};
|
||||
worker.postMessage(this.result);
|
||||
});
|
||||
reader.readAsArrayBuffer(readfile);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Jimp browser example 4</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Demonstrates how to write a text over an image</h1>
|
||||
<script src="../lib/jimp.js"></script>
|
||||
<img id="pic" style="float: left; margin: 0px 20px 5px 0px" />
|
||||
<script>
|
||||
function writePic() {
|
||||
Jimp.read("lenna.png")
|
||||
.then(function (lenna) {
|
||||
var fntName = "FONT_SANS_" + fntSize.value + "_" + txtColor.value;
|
||||
var x = parseInt(txtX.value);
|
||||
var y = parseInt(txtY.value);
|
||||
var w = parseInt(txtW.value);
|
||||
console.log();
|
||||
Jimp.loadFont(Jimp[fntName])
|
||||
.then(function (font) {
|
||||
lenna
|
||||
.print(font, x, y, txtField.value, w)
|
||||
.getBase64(Jimp.AUTO, function (err, src) {
|
||||
if (err) {
|
||||
alert(err.message);
|
||||
throw err;
|
||||
}
|
||||
pic.setAttribute("src", src);
|
||||
});
|
||||
})
|
||||
.catch(function (err) {
|
||||
throw err;
|
||||
});
|
||||
})
|
||||
.catch(function (err) {
|
||||
alert("Image load fail.\n" + err.message);
|
||||
throw err;
|
||||
});
|
||||
return false;
|
||||
}
|
||||
writePic();
|
||||
</script>
|
||||
<textarea rows="4" cols="80" id="txtField">Hi! I'm Lenna.</textarea>
|
||||
<br />
|
||||
<label
|
||||
>Size:
|
||||
<select id="fntSize">
|
||||
<option>8</option>
|
||||
<option>16</option>
|
||||
<option>32</option>
|
||||
<option>64</option>
|
||||
<option>128</option>
|
||||
</select></label
|
||||
>
|
||||
<br />
|
||||
<label
|
||||
>Color:
|
||||
<select id="txtColor">
|
||||
<option>BLACK</option>
|
||||
<option>WHITE</option>
|
||||
</select></label
|
||||
>
|
||||
<br />
|
||||
<label>pos X: <input id="txtX" value="0" size="3" />px</label> <br />
|
||||
<label>pos Y: <input id="txtY" value="0" size="3" />px</label> <br />
|
||||
<label>max Width: <input id="txtW" value="400" size="3" />px</label> <br />
|
||||
<input
|
||||
type="button"
|
||||
id="btWrite"
|
||||
onclick="writePic(); return false"
|
||||
value="Write"
|
||||
/>
|
||||
</body>
|
||||
</html>
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/* eslint-env worker */
|
||||
/* global Jimp */
|
||||
|
||||
importScripts("../lib/jimp.js");
|
||||
|
||||
self.addEventListener("message", (e) => {
|
||||
Jimp.read(e.data).then((lenna) => {
|
||||
lenna
|
||||
.resize(256, Jimp.AUTO) // resize
|
||||
.quality(60) // set JPEG quality
|
||||
.greyscale() // set greyscale
|
||||
.getBase64(Jimp.AUTO, (err, src) => {
|
||||
if (err) throw err;
|
||||
self.postMessage(src);
|
||||
self.close();
|
||||
});
|
||||
});
|
||||
});
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 463 KiB |
+49
@@ -0,0 +1,49 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Jimp browser example 1</title>
|
||||
</head>
|
||||
<body>
|
||||
<!-- Demonstrates loading a local file using Jimp on the main thread -->
|
||||
<script src="../lib/jimp.js"></script>
|
||||
<script>
|
||||
function dropShadow(x, y, b, a) {
|
||||
var img = new Jimp(
|
||||
this.bitmap.width + Math.abs(x * 2) + b * 2,
|
||||
this.bitmap.height + Math.abs(y * 2) + b * 2
|
||||
);
|
||||
var orig = this.clone();
|
||||
this.scan(
|
||||
0,
|
||||
0,
|
||||
this.bitmap.width,
|
||||
this.bitmap.height,
|
||||
function (x, y, idx) {
|
||||
this.bitmap.data[idx + 0] = 0;
|
||||
this.bitmap.data[idx + 1] = 0;
|
||||
this.bitmap.data[idx + 2] = 0;
|
||||
this.bitmap.data[idx + 3] = this.bitmap.data[idx + 3] * a;
|
||||
}
|
||||
);
|
||||
// this.resize(this.bitmap.width + Math.abs(x) + b, this.bitmap.height + Math.abs(y) + b);
|
||||
|
||||
var x1 = Math.max(x * -1, 0) + b;
|
||||
var y1 = Math.max(y * -1, 0) + b;
|
||||
img.composite(this, x1, y1);
|
||||
img.blur(b);
|
||||
img.composite(orig, x1 - x, y1 - y);
|
||||
//img.autocrop();
|
||||
return img;
|
||||
}
|
||||
Jimp.read("dice.png").then(function (img) {
|
||||
console.log(img.getMIME(), img.getExtension());
|
||||
var img = dropShadow.call(img, 20, 20, 20, 0.3);
|
||||
img.getBase64(Jimp.AUTO, function (err, src) {
|
||||
var img = document.createElement("img");
|
||||
img.setAttribute("src", src);
|
||||
document.body.appendChild(img);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
+3
File diff suppressed because one or more lines are too long
+277
@@ -0,0 +1,277 @@
|
||||
/*!
|
||||
* The buffer module from node.js, for the browser.
|
||||
*
|
||||
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
* The buffer module from node.js, for the browser.
|
||||
*
|
||||
* @author Feross Aboukhadijeh <https://feross.org>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Timm
|
||||
*
|
||||
* Immutability helpers with fast reads and acceptable writes.
|
||||
*
|
||||
* @copyright Guillermo Grau Panea 2016
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||
|
||||
/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* cie94.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* ciede2000.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* cmetric.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* common.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* constants.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* ditherErrorDiffusionArray.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* euclidean.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* helper.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* hueStatistics.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* iq.ts - Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* lab2rgb.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* lab2xyz.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* manhattanNeuQuant.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* nearestColor.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* palette.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* pngQuant.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* point.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* pointContainer.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* rgb2hsl.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* rgb2lab.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* rgb2xyz.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* ssim.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* wuQuant.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* xyz2lab.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* xyz2rgb.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve
|
||||
* MIT License
|
||||
*
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to
|
||||
* deal in the Software without restriction, including without limitation the
|
||||
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
* sell copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
||||
* IN THE SOFTWARE.
|
||||
*
|
||||
* riemersma.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve TypeScript port:
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* colorHistogram.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve TypeScript port:
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* neuquant.ts - part of Image Quantization Library
|
||||
*/
|
||||
|
||||
/**
|
||||
* @preserve TypeScript port:
|
||||
* Copyright 2015-2018 Igor Bezkrovnyi
|
||||
* All rights reserved. (MIT Licensed)
|
||||
*
|
||||
* rgbquant.ts - part of Image Quantization Library
|
||||
*/
|
||||
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user