Guest User

Untitled

a guest
Oct 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. /**
  2. * $ npm i -S node-vibrant
  3. */
  4. import { Injectable } from '@angular/core';
  5. import Vibrant from 'node-vibrant';
  6.  
  7. @Injectable()
  8. export class PaletteService {
  9. constructor() { }
  10.  
  11. /**
  12. *
  13. * @param image :document.findElementById('image');
  14. */
  15. getColors(image) {
  16. try {
  17. var vibrant = new Vibrant(image);
  18. return vibrant.getPalette()
  19. .then(palette => {
  20. return {
  21. vibrant: (palette.Vibrant) ? palette.Vibrant.getHex() : '',
  22. muted: (palette.Vibrant) ? palette.Vibrant.getHex() : '',
  23. darkVibrant: (palette.DarkVibrant) ? palette.DarkVibrant.getHex() : '',
  24. darkMuted: (palette.DarkMuted) ? palette.DarkMuted.getHex() : '',
  25. lightVibrant: (palette.LightVibrant) ? palette.LightVibrant.getHex() : '',
  26. lightMuted: (palette.LightMuted) ? palette.LightMuted.getHex() : ''
  27. };
  28. });
  29. } catch (error) {
  30. throw 'Error';
  31. }
  32. }
  33. }
Add Comment
Please, Sign In to add comment