splashy 5.1.46 → 6.0.0-0
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/LICENSE +0 -0
- package/README.md +6 -4
- package/package.json +19 -17
- package/src/index.js +42 -29
- package/src/vibrant.js +0 -62
package/LICENSE
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -22,7 +22,7 @@ $ npm install splashy --save
|
|
|
22
22
|
### From URL
|
|
23
23
|
|
|
24
24
|
```js
|
|
25
|
-
(async () => {
|
|
25
|
+
;(async () => {
|
|
26
26
|
const splashy = require('splashy')
|
|
27
27
|
const got = require('got')
|
|
28
28
|
|
|
@@ -38,7 +38,7 @@ $ npm install splashy --save
|
|
|
38
38
|
### From Buffer
|
|
39
39
|
|
|
40
40
|
```js
|
|
41
|
-
(async () => {
|
|
41
|
+
;(async () => {
|
|
42
42
|
const splashy = require('splashy')
|
|
43
43
|
const path = require('path')
|
|
44
44
|
const fs = require('fs')
|
|
@@ -58,7 +58,7 @@ $ npm install splashy --save
|
|
|
58
58
|
|
|
59
59
|
#### input
|
|
60
60
|
|
|
61
|
-
|
|
61
|
+
_Required_<br>
|
|
62
62
|
Type: [ImageSource](https://github.com/akfish/node-vibrant#imagesource)
|
|
63
63
|
|
|
64
64
|
The raw content for detecting the color information.
|
|
@@ -71,7 +71,9 @@ The raw content for detecting the color information.
|
|
|
71
71
|
## License
|
|
72
72
|
|
|
73
73
|
**microlink-function** © [Microlink](https://microlink.io), released under the [MIT](https://github.com/microlink/microlink-function/blob/master/LICENSE.md) License.<br>
|
|
74
|
+
|
|
74
75
|
Authored and maintained by [Kiko Beats](https://kikobeats.com) with help from [contributors](https://github.com/microlink/microlink-function/contributors).
|
|
75
76
|
|
|
76
|
-
|
|
77
|
+
Special thanks to [Tim Carry](https://github.com/pixelastic) for writing the benchmark and [Lokesh Dhakar](https://github.com/lokesh) for the original code implementation.
|
|
77
78
|
|
|
79
|
+
> [microlink.io](https://microlink.io) · GitHub [microlinkhq](https://github.com/microlinkhq) · X [@microlinkhq](https://x.com/microlinkhq)
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "splashy",
|
|
3
3
|
"description": "Given an image, extract predominant & palette colors",
|
|
4
4
|
"homepage": "https://github.com/microlinkhq/splashy",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "6.0.0-0",
|
|
6
6
|
"main": "src/index.js",
|
|
7
7
|
"author": {
|
|
8
8
|
"name": "Kiko Beats",
|
|
@@ -41,9 +41,11 @@
|
|
|
41
41
|
"url"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
+
"@lokesh.dhakar/quantize": "~1.4.0",
|
|
44
45
|
"debug-logfmt": "~1.2.3",
|
|
46
|
+
"ndarray": "~1.0.19",
|
|
45
47
|
"node-addon-api": "~8.3.0",
|
|
46
|
-
"node-gyp": "~
|
|
48
|
+
"node-gyp": "~11.0.0",
|
|
47
49
|
"node-vibrant": "~3.2.1-alpha.1",
|
|
48
50
|
"serialize-error": "~8.1.0",
|
|
49
51
|
"sharp": "0.33.5"
|
|
@@ -71,20 +73,6 @@
|
|
|
71
73
|
"files": [
|
|
72
74
|
"src"
|
|
73
75
|
],
|
|
74
|
-
"scripts": {
|
|
75
|
-
"clean": "rm -rf node_modules",
|
|
76
|
-
"contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
|
|
77
|
-
"dev": "nodemon --exec \"npm start\" -e \"js\"",
|
|
78
|
-
"lint": "standard-markdown README.md && standard",
|
|
79
|
-
"postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
|
|
80
|
-
"preinstall": "npx bin-version-check-cli magick \">=7\"",
|
|
81
|
-
"pretest": "npm run lint",
|
|
82
|
-
"release": "standard-version -a",
|
|
83
|
-
"release:github": "conventional-github-releaser -p angular",
|
|
84
|
-
"release:tags": "git push --follow-tags origin HEAD:master",
|
|
85
|
-
"start": "node index.js",
|
|
86
|
-
"test": "c8 ava"
|
|
87
|
-
},
|
|
88
76
|
"license": "MIT",
|
|
89
77
|
"commitlint": {
|
|
90
78
|
"extends": [
|
|
@@ -111,5 +99,19 @@
|
|
|
111
99
|
"simple-git-hooks": {
|
|
112
100
|
"commit-msg": "npx commitlint --edit",
|
|
113
101
|
"pre-commit": "npx nano-staged"
|
|
102
|
+
},
|
|
103
|
+
"scripts": {
|
|
104
|
+
"clean": "rm -rf node_modules",
|
|
105
|
+
"contributors": "(npx git-authors-cli && npx finepack && git add package.json && git commit -m 'build: contributors' --no-verify) || true",
|
|
106
|
+
"dev": "nodemon --exec \"npm start\" -e \"js\"",
|
|
107
|
+
"lint": "standard-markdown README.md && standard",
|
|
108
|
+
"postrelease": "npm run release:tags && npm run release:github && (ci-publish || npm publish --access=public)",
|
|
109
|
+
"preinstall": "npx bin-version-check-cli magick \">=7\"",
|
|
110
|
+
"pretest": "npm run lint",
|
|
111
|
+
"release": "standard-version -a",
|
|
112
|
+
"release:github": "conventional-github-releaser -p angular",
|
|
113
|
+
"release:tags": "git push --follow-tags origin HEAD:master",
|
|
114
|
+
"start": "node index.js",
|
|
115
|
+
"test": "c8 ava"
|
|
114
116
|
}
|
|
115
|
-
}
|
|
117
|
+
}
|
package/src/index.js
CHANGED
|
@@ -1,34 +1,47 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
3
|
+
const quantize = require('@lokesh.dhakar/quantize')
|
|
4
|
+
const ndarray = require('ndarray')
|
|
5
|
+
const sharp = require('sharp')
|
|
6
|
+
|
|
7
|
+
async function getPixels (buffer) {
|
|
8
|
+
const { data, info } = await sharp(buffer)
|
|
9
|
+
.ensureAlpha()
|
|
10
|
+
.raw()
|
|
11
|
+
.toBuffer({ resolveWithObject: true })
|
|
12
|
+
|
|
13
|
+
return ndarray(
|
|
14
|
+
new Uint8Array(data.buffer, data.byteOffset, data.length),
|
|
15
|
+
[info.width, info.height, 4],
|
|
16
|
+
[4, (4 * info.width) | 0, 1],
|
|
17
|
+
0
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function createPixelArray (pixels, pixelCount, quality = 10) {
|
|
22
|
+
const pixelArray = []
|
|
23
|
+
|
|
24
|
+
for (let i = 0, offset; i < pixelCount; i += quality) {
|
|
25
|
+
offset = i * 4
|
|
26
|
+
const r = pixels[offset]
|
|
27
|
+
const g = pixels[offset + 1]
|
|
28
|
+
const b = pixels[offset + 2]
|
|
29
|
+
const a = pixels[offset + 3]
|
|
30
|
+
|
|
31
|
+
if ((a === undefined || a >= 125) && !(r > 250 && g > 250 && b > 250)) {
|
|
32
|
+
pixelArray.push([r, g, b])
|
|
33
|
+
}
|
|
31
34
|
}
|
|
32
35
|
|
|
33
|
-
return
|
|
36
|
+
return pixelArray
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const toHex = ([r, g, b]) => '#' + (b | (g << 8) | (r << 16) | (1 << 24)).toString(16).slice(1)
|
|
40
|
+
|
|
41
|
+
module.exports = async function (buffer) {
|
|
42
|
+
const imgData = await getPixels(await sharp(buffer).toBuffer())
|
|
43
|
+
const pixelCount = imgData.shape[0] * imgData.shape[1]
|
|
44
|
+
const pixelArray = createPixelArray(imgData.data, pixelCount)
|
|
45
|
+
const cmap = quantize(pixelArray, 10) // internal tuning
|
|
46
|
+
return cmap.palette().slice(0, 6).map(toHex)
|
|
34
47
|
}
|
package/src/vibrant.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const { ImageBase } = require('@vibrant/image')
|
|
4
|
-
const Vibrant = require('node-vibrant')
|
|
5
|
-
const sharp = require('sharp')
|
|
6
|
-
|
|
7
|
-
class SharpImage extends ImageBase {
|
|
8
|
-
constructor () {
|
|
9
|
-
super(...arguments)
|
|
10
|
-
this._image = undefined
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
async load (image) {
|
|
14
|
-
if (typeof image === 'string' || image instanceof Buffer) {
|
|
15
|
-
const { data, info } = await sharp(image)
|
|
16
|
-
// resizing the image before processing leads to more consistent (and much shorter) processing times.
|
|
17
|
-
.resize(200, 200, { fit: 'inside', withoutEnlargement: true })
|
|
18
|
-
.ensureAlpha()
|
|
19
|
-
.raw()
|
|
20
|
-
.toBuffer({ resolveWithObject: true })
|
|
21
|
-
|
|
22
|
-
this._image = {
|
|
23
|
-
width: info.width,
|
|
24
|
-
height: info.height,
|
|
25
|
-
data
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return this
|
|
29
|
-
} else {
|
|
30
|
-
return Promise.reject(
|
|
31
|
-
new Error('Cannot load image from HTMLImageElement in node environment')
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
clear () {}
|
|
37
|
-
|
|
38
|
-
update () {}
|
|
39
|
-
|
|
40
|
-
getWidth () {
|
|
41
|
-
return this._image.width
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getHeight () {
|
|
45
|
-
return this._image.height
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
resize () {}
|
|
49
|
-
|
|
50
|
-
getPixelCount () {
|
|
51
|
-
const { width, height } = this._image
|
|
52
|
-
return width * height
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
getImageData () {
|
|
56
|
-
return this._image
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
remove () {}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
module.exports = input => new Vibrant(input, { ImageClass: SharpImage })
|