Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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");
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 '';
});
},
};
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;
}
function retrieveFastAverageColor() {
if ( ! retrieveFastAverageColor.fastAverageColor ) {
retrieveFastAverageColor.fastAverageColor = new FastAverageColor();
}
return retrieveFastAverageColor.fastAverageColor;
}
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);
}