Skip to content

Commit

Permalink
feat: make a better blur gradient
Browse files Browse the repository at this point in the history
  • Loading branch information
gloaysa committed Mar 22, 2024
1 parent 5f8db6a commit cf55492
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/components/MediaDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,24 @@ export const MediaDisplay: FunctionComponent<IMediaPlayerProps> = ({ plexamp, is

if (plexamp.metadata?.thumb) {
colorThief
.getPaletteAsync(plexamp.metadata.thumb, 5)
.getPaletteAsync(plexamp.metadata.thumb, 4, { quality: 1, colorType: "array" }) // Request 4 colors for the 4 gradients
.then((palette) => {
const gradientColors = palette.join(", ");
const linearGradient = `radial-gradient(circle at center, ${gradientColors})`;
setBackgroundGradient(linearGradient);
// Convert each RGB array to a RGBA string with 80% opacity
const gradientColors = palette.map((rgb) => `rgba(${rgb[0]}, ${rgb[1]}, ${rgb[2]}, 0.8)`);

// Create 4 radial gradients, each with a different color and position
const gradients = [
`radial-gradient(circle at left bottom, ${gradientColors[2]} 0px, transparent 80%)`,
`radial-gradient(circle at right bottom, ${gradientColors[3]} 0px, transparent 80%)`,
`radial-gradient(circle at right top, ${gradientColors[2]} 0px, transparent 80%)`,
`radial-gradient(circle at left top, ${gradientColors[3]} 0px, transparent 80%)`,
];

// Join the gradients into a single background image
const backgroundImage = gradients.join(", ");

console.log(backgroundImage);
setBackgroundGradient(backgroundImage);
})
.catch((error) => console.error(error));
}
Expand Down

0 comments on commit cf55492

Please sign in to comment.