From d48654cfeb041e36c81be3a0e0eba6d6b930987b Mon Sep 17 00:00:00 2001 From: Jensen Bernard Date: Sun, 5 Mar 2017 15:11:08 +0100 Subject: [PATCH] feat: Possible to extract the top color from the site --- README.md | 4 ++-- package.json | 2 +- src/index.js | 4 ++-- test/index.spec.js | 10 ++++++---- yarn.lock | 31 +++++++++++++++++++++++++++---- 5 files changed, 38 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 70c5710..de244a1 100644 --- a/README.md +++ b/README.md @@ -13,10 +13,10 @@ ```sh # Extract color schemes via terminal (optional output file). -# See the images and result below. +# See the images and result below. The top is the color at the top of the site. $ npm install -g site-scheme $ site-scheme --url 'http://toledo.kuleuven.be' --number 5 --output 'output.png' -# Prints: [{"r":244,"g":245,"b":245,"a":255},{"r":29,"g":139,"b":177,"a":255},...] +# Prints: {top:{"r":244,"g":245,"b":245,"a":255},colors:[{"r":29,"g":139,"b":177,"a":255},...] ``` ```js diff --git a/package.json b/package.json index 587d924..4b9551e 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "bluebird": "^3.4.7", "chalk": "^1.1.3", "color-blocks": "^0.2.0", - "color-extract": "^0.2.0", + "color-extract": "^0.3.0", "commander": "^2.9.0", "commitizen": "^2.9.6", "cz-conventional-changelog": "^2.0.0", diff --git a/src/index.js b/src/index.js index 3a573f6..b222437 100644 --- a/src/index.js +++ b/src/index.js @@ -42,12 +42,12 @@ export default (url: string, amount: number, output: ?string) => if (isUrl(url)) { capture(url, CACHEA) .then(() => resizeCache()) - .then(() => getProminentColors(CACHEB, amount)) + .then(() => getProminentColors(CACHEB, amount, true)) .then((colors) => { if (output) { const aop = path.resolve(process.cwd(), output); const outputPath = path.extname(aop) === '.png' ? aop : path.resolve(aop, 'output.png'); - createColorPattern(50, colors, outputPath).then(() => { + createColorPattern(50, [colors.top, ...colors.colors], outputPath).then(() => { resolve(colors); }).catch(reject); } else { resolve(colors); } diff --git a/test/index.spec.js b/test/index.spec.js index f7c2053..22b76c3 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -7,8 +7,9 @@ describe('Default tests', () => { it('should extract colors with output', (done) => { const output = path.resolve(__dirname, 'output.png'); extract('https://toledo.kuleuven.be', 5, output).then((colors) => { - expect(colors).to.be.an('array'); - expect(colors).to.have.length(5); + expect(colors.colors).to.be.an('array'); + expect(colors.colors).to.have.length(4); + expect(!!colors.top).to.equal(true); expect(fse.existsSync(output)).to.equal(true); fse.removeSync(output); done(); @@ -17,8 +18,9 @@ describe('Default tests', () => { it('should extract colors without output', (done) => { const output = path.resolve(__dirname, 'output.png'); extract('https://toledo.kuleuven.be', 5).then((colors) => { - expect(colors).to.be.an('array'); - expect(colors).to.have.length(5); + expect(colors.colors).to.be.an('array'); + expect(colors.colors).to.have.length(4); + expect(!!colors.top).to.equal(true); expect(fse.existsSync(output)).to.equal(false); done(); }).catch(done); diff --git a/yarn.lock b/yarn.lock index cfc363f..687a9ae 100644 --- a/yarn.lock +++ b/yarn.lock @@ -932,6 +932,12 @@ cli-width@^2.0.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cli-width/-/cli-width-2.1.0.tgz#b234ca209b29ef66fc518d9b98d5847b00edf00a" +cli@^0.4.5: + version "0.4.5" + resolved "https://registry.yarnpkg.com/cli/-/cli-0.4.5.tgz#78f9485cd161b566e9a6c72d7170c4270e81db61" + dependencies: + glob ">= 3.1.4" + cliui@^2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/cliui/-/cliui-2.1.0.tgz#4b475760ff80264c762c3a1719032e91c7fea0d1" @@ -977,20 +983,33 @@ color-blocks@^0.2.0: cz-conventional-changelog "^2.0.0" jimp "^0.2.27" -color-extract@^0.2.0: - version "0.2.0" - resolved "https://registry.yarnpkg.com/color-extract/-/color-extract-0.2.0.tgz#997087f262a7c59b390a0fb2b80f8cb26c851f7d" +color-difference@^0.3.4: + version "0.3.4" + resolved "https://registry.yarnpkg.com/color-difference/-/color-difference-0.3.4.tgz#95edcbacc64e382c2969741744a6508b3f94488f" + dependencies: + cli "^0.4.5" + color-model "^0.2.0" + +color-extract@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/color-extract/-/color-extract-0.3.0.tgz#fd58d76aa8d66ffc91d318ac38287cf5da2b9c32" dependencies: chalk "^1.1.3" clusterfck "^0.6.0" + color-difference "^0.3.4" commander "^2.9.0" commitizen "^2.9.6" cz-conventional-changelog "^2.0.0" get-pixels "^3.3.0" get-rgba-palette "^2.0.1" jimp "^0.2.27" + onecolor "^3.0.4" winston "^2.3.0" +color-model@^0.2.0: + version "0.2.2" + resolved "https://registry.yarnpkg.com/color-model/-/color-model-0.2.2.tgz#c179796f0b654caee1720207e74d9177dee24a17" + colors@1.0.x: version "1.0.3" resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b" @@ -1949,7 +1968,7 @@ glob@7.0.5: once "^1.3.0" path-is-absolute "^1.0.0" -glob@7.1.1, glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.0.6: +glob@7.1.1, "glob@>= 3.1.4", glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.0.6: version "7.1.1" resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.1.tgz#805211df04faaf1c63a3600306cdf5ade50b2ec8" dependencies: @@ -3080,6 +3099,10 @@ once@~1.3.0, once@~1.3.3: dependencies: wrappy "1" +onecolor@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/onecolor/-/onecolor-3.0.4.tgz#75a46f80da6c7aaa5b4daae17a47198bd9652494" + onetime@^1.0.0: version "1.1.0" resolved "https://registry.yarnpkg.com/onetime/-/onetime-1.1.0.tgz#a1f7838f8314c516f05ecefcbc4ccfe04b4ed789"