diff --git a/gatsby-node.js b/gatsby-node.js index 7dd5fe7..6719a87 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -100,15 +100,19 @@ function processColors(vibrantData, imagePath) { // } // } -function transformMetaToNodeData(metaData, vibrantData, imagePath) { +function transformMetaToNodeData(metaData, vibrantData, imagePath, { r, g, b }) { const vibrant = vibrantData ? processColors(vibrantData, imagePath) : null; - let dominantHue = vibrantData.Vibrant.getHsl()[0] * 360; - + const vibrantHue = vibrantData.Vibrant.getHsl()[0] * 360; + let dominantHue = chroma(r,g,b).hsl(); + if (isNaN(dominantHue[0])) { + dominantHue[0] = 0 + } return { dateTaken: metaData.DateTimeOriginal, meta: metaData, vibrant, - dominantHue, + vibrantHue, + dominantHue }; } @@ -121,7 +125,9 @@ exports.onCreateNode = async function ({ node, actions }) { // icc: true }); - const resizedImage = await sharp(node.absolutePath) + const sharpImage = sharp(node.absolutePath); + const { dominant } = await sharpImage.stats(); + const resizedImage = await sharpImage .resize({ width: 3000, height: 3000, @@ -139,7 +145,8 @@ exports.onCreateNode = async function ({ node, actions }) { value: transformMetaToNodeData( metaData, vibrantData, - node.absolutePath + node.absolutePath, + dominant ), }); } diff --git a/src/components/MasonryGallery.js b/src/components/MasonryGallery.js index 1a7cc21..da47bc0 100644 --- a/src/components/MasonryGallery.js +++ b/src/components/MasonryGallery.js @@ -6,10 +6,12 @@ import { getAspectRatio, getName } from "../utils"; import useBreakpoint from "use-breakpoint"; import themeBreakpoints from "../breakpoints"; +import classNames from "classnames"; const MasonryGallery = ({ images, aspectsByBreakpoint: aspectTargetsByBreakpoint, + debug, }) => { const breakpoints = React.useMemo( () => R.pick(R.keys(aspectTargetsByBreakpoint), themeBreakpoints), @@ -99,20 +101,42 @@ const MasonryGallery = ({ const widthNumber = ((ar / rowAspectRatioSum) * 100).toFixed(7); const width = `${widthNumber}%`; + console.log(image.fields.imageMeta.dominantHue); return ( + {debug && ( + + hsl( + {image.fields.imageMeta.dominantHue[0]},{' '} + {(image.fields.imageMeta.dominantHue[1] * 100).toFixed(2)}%,{' '} + {(image.fields.imageMeta.dominantHue[2] * 100).toFixed(2)}% ) + + )} diff --git a/src/pages/photogallery.js b/src/pages/photogallery.js index 7bb6e72..edeb99c 100644 --- a/src/pages/photogallery.js +++ b/src/pages/photogallery.js @@ -1,4 +1,5 @@ import * as React from "react"; +import * as R from "ramda"; import { graphql, Link } from "gatsby"; import { navigate } from "gatsby"; import { Helmet } from "react-helmet"; @@ -6,9 +7,15 @@ import { Helmet } from "react-helmet"; import MasonryGallery from "../components/MasonryGallery"; const GalleryPage = ({ data }) => { + const [debug, setDebug] = React.useState(false); + const images = React.useMemo( - () => data.allFile.edges.map((edge) => edge.node, [data]), - [data] + () => + R.pipe( + R.map((edge) => edge.node), + debug ? R.sortBy(R.path(["fields", "imageMeta", "dominantHue", 0])) : R.identity + )(data.allFile.edges), + [data, debug] ); return ( @@ -39,9 +46,24 @@ const GalleryPage = ({ data }) => {
-

- Photo Gallery -

+
+

+ Photo Gallery +

+ {window && window.location.hash.includes("debug") ? ( +
+ +
+ ) : null} +
{ lg: 4, xl: 5, }} + debug={debug} images={images} />
@@ -62,7 +85,7 @@ export const query = graphql` query GalleryPageQuery { allFile( filter: { sourceInstanceName: { eq: "gallery" } } - sort: { fields: fields___imageMeta___dominantHue, order: DESC } + sort: { fields: fields___imageMeta___vibrantHue, order: DESC } ) { edges { node { @@ -85,6 +108,9 @@ export const query = graphql` meta { ObjectName } + vibrant { + Vibrant + } } } }