How to use fast-average-color - 5 common examples

To help you get started, we’ve selected a few fast-average-color examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github canonical-web-and-design / snapcraft.io / static / js / libs / colours.js View on Github external
function extractAndSet(image, parent) {
    const fac = new Fac();
    const colour = fac.getColor(image, { defaultColor: [238, 238, 238] });

    // If the average colour is black, the logo is probably black,
    // se we should invert things. Same for white
    if (colour.hex === "#000000") {
      colour.rgb = "rgb(238,238,238)";
      colour.isDark = false;
      colour.isLight = true;
    } else if (colour.hex === "#ffffff") {
      colour.rgb = "rgb(0,0,0)";
      colour.isDark = true;
      colour.isLight = false;
    }
    parent.style.backgroundColor = colour.rgb;
    parent.classList.remove("is-light");
    parent.classList.add(colour.isDark ? "is-dark" : "is-light");
github stellarterm / stellarterm / src / lib / driver / Session.js View on Github external
getAverageColor: (imageUrl, code, domain) => {
            const fac = new FastAverageColor();
            const img = document.createElement('img');
            img.src = `${imageUrl}?rnd${Math.random()}`;
            img.crossOrigin = 'Anonymous';

            return fac.getColorAsync(img)
                .then(col => col.hex)
                .catch(() => {
                    console.warn(`Can not calculate background color for ${code} (${domain}). Reason: CORS Policy`);
                    return '';
                });
        },
    };
github carlelieser / Flixerr / assets / js / movie-item.jsx View on Github external
handleImage = () => {
        let posterImage = this.createNewImage(this.props.movie.flixerr_data.poster_path);
        let colorImage = this.createNewImage(this.props.movie.flixerr_data.blurry_backdrop_path);
        let fac = new FastAverageColor();

        fac
            .getColorAsync(colorImage, {algorithm: "sqrt"})
            .then((color) => {
                if (!this.unMounting) {
                    this.setState({averageColor: color});
                }
            })
            .catch((err) => console.log(err));

        if (this.props.fallback) {
            let backdropImage = this.createNewImage(this.props.movie.flixerr_data.backdrop_path);
            backdropImage.onload = this.loadImage;
        } else {
            posterImage.onload = this.loadImage;
        }
github WordPress / gutenberg / packages / block-library / src / cover / edit.js View on Github external
function retrieveFastAverageColor() {
	if ( ! retrieveFastAverageColor.fastAverageColor ) {
		retrieveFastAverageColor.fastAverageColor = new FastAverageColor();
	}
	return retrieveFastAverageColor.fastAverageColor;
}
github iondrimba / pwa-music-player / src / components / AlbumCover / index.js View on Github external
constructor(props) {
    super(props);

    this.loader = React.createRef();
    this.image = React.createRef();
    this.view = React.createRef();

    this.fac = new FastAverageColor();

    this._onLoadDummyImage = this._onLoadDummyImage.bind(this);
  }

fast-average-color

A simple library that calculates the average color of images, videos and canvas in browser environment.

MIT
Latest version published 1 year ago

Package Health Score

57 / 100
Full package analysis

Popular fast-average-color functions