Skip to content

Commit

Permalink
feat: Possible to extract the top color from the site
Browse files Browse the repository at this point in the history
  • Loading branch information
Jense5 committed Mar 5, 2017
1 parent 796ec95 commit d48654c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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); }
Expand Down
10 changes: 6 additions & 4 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down
31 changes: 27 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"

[email protected]:
version "1.0.3"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
Expand Down Expand Up @@ -1949,7 +1968,7 @@ [email protected]:
once "^1.3.0"
path-is-absolute "^1.0.0"

[email protected], glob@^7.0.0, glob@^7.0.3, glob@^7.0.5, glob@^7.0.6:
[email protected], "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:
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit d48654c

Please sign in to comment.