Skip to content

Commit

Permalink
remove the conversion to hex as color has hex already
Browse files Browse the repository at this point in the history
  • Loading branch information
draganescu committed Aug 30, 2023
1 parent 69eab9f commit 63e1426
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions packages/block-library/src/cover/shared.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,7 @@ export function attributesFromMedia( setAttributes, dimRatio ) {
mediaType = media.type;
}

let customOverlayColor = await getAverageMediaColor( media.url );
/*eslint no-bitwise: ["error", { "allow": ["|","<<"] }] */
customOverlayColor = customOverlayColor
? '#' +
( customOverlayColor.r | ( 1 << 8 ) ).toString( 16 ).slice( 1 ) +
( customOverlayColor.g | ( 1 << 8 ) ).toString( 16 ).slice( 1 ) +
( customOverlayColor.b | ( 1 << 8 ) ).toString( 16 ).slice( 1 )
: customOverlayColor;
const customOverlayColor = await getAverageMediaColor( media.url );

setAttributes( {
isDark,
Expand Down Expand Up @@ -219,9 +212,7 @@ export async function getAverageMediaColor( url ) {
undefined,
url
);
const {
value: [ r, g, b, a ],
} = await retrieveFastAverageColor().getColorAsync( url, {
const color = await retrieveFastAverageColor().getColorAsync( url, {
// Previously the default color was white, but that changed
// in v6.0.0 so it has to be manually set now.
defaultColor: [ 255, 255, 255, 255 ],
Expand All @@ -231,7 +222,7 @@ export async function getAverageMediaColor( url ) {
crossOrigin: imgCrossOrigin,
} );
// FAC uses 0-255 for alpha, but colord expects 0-1.
return { r, g, b, a: a / 255 };
return color.hex;
} catch ( error ) {
// If there's an error, just assume the image is dark.
return false;
Expand Down

0 comments on commit 63e1426

Please sign in to comment.