Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * $ npm i -S node-vibrant
- */
- import { Injectable } from '@angular/core';
- import Vibrant from 'node-vibrant';
- @Injectable()
- export class PaletteService {
- constructor() { }
- /**
- *
- * @param image :document.findElementById('image');
- */
- getColors(image) {
- try {
- var vibrant = new Vibrant(image);
- return vibrant.getPalette()
- .then(palette => {
- return {
- vibrant: (palette.Vibrant) ? palette.Vibrant.getHex() : '',
- muted: (palette.Vibrant) ? palette.Vibrant.getHex() : '',
- darkVibrant: (palette.DarkVibrant) ? palette.DarkVibrant.getHex() : '',
- darkMuted: (palette.DarkMuted) ? palette.DarkMuted.getHex() : '',
- lightVibrant: (palette.LightVibrant) ? palette.LightVibrant.getHex() : '',
- lightMuted: (palette.LightMuted) ? palette.LightMuted.getHex() : ''
- };
- });
- } catch (error) {
- throw 'Error';
- }
- }
- }
Add Comment
Please, Sign In to add comment