add debug for dominant hue
This commit is contained in:
parent
fd4ae4af7b
commit
8033aeca0f
@ -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;
|
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 {
|
return {
|
||||||
dateTaken: metaData.DateTimeOriginal,
|
dateTaken: metaData.DateTimeOriginal,
|
||||||
meta: metaData,
|
meta: metaData,
|
||||||
vibrant,
|
vibrant,
|
||||||
dominantHue,
|
vibrantHue,
|
||||||
|
dominantHue
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +125,9 @@ exports.onCreateNode = async function ({ node, actions }) {
|
|||||||
// icc: true
|
// icc: true
|
||||||
});
|
});
|
||||||
|
|
||||||
const resizedImage = await sharp(node.absolutePath)
|
const sharpImage = sharp(node.absolutePath);
|
||||||
|
const { dominant } = await sharpImage.stats();
|
||||||
|
const resizedImage = await sharpImage
|
||||||
.resize({
|
.resize({
|
||||||
width: 3000,
|
width: 3000,
|
||||||
height: 3000,
|
height: 3000,
|
||||||
@ -139,7 +145,8 @@ exports.onCreateNode = async function ({ node, actions }) {
|
|||||||
value: transformMetaToNodeData(
|
value: transformMetaToNodeData(
|
||||||
metaData,
|
metaData,
|
||||||
vibrantData,
|
vibrantData,
|
||||||
node.absolutePath
|
node.absolutePath,
|
||||||
|
dominant
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -6,10 +6,12 @@ import { getAspectRatio, getName } from "../utils";
|
|||||||
import useBreakpoint from "use-breakpoint";
|
import useBreakpoint from "use-breakpoint";
|
||||||
|
|
||||||
import themeBreakpoints from "../breakpoints";
|
import themeBreakpoints from "../breakpoints";
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
const MasonryGallery = ({
|
const MasonryGallery = ({
|
||||||
images,
|
images,
|
||||||
aspectsByBreakpoint: aspectTargetsByBreakpoint,
|
aspectsByBreakpoint: aspectTargetsByBreakpoint,
|
||||||
|
debug,
|
||||||
}) => {
|
}) => {
|
||||||
const breakpoints = React.useMemo(
|
const breakpoints = React.useMemo(
|
||||||
() => R.pick(R.keys(aspectTargetsByBreakpoint), themeBreakpoints),
|
() => R.pick(R.keys(aspectTargetsByBreakpoint), themeBreakpoints),
|
||||||
@ -99,20 +101,42 @@ const MasonryGallery = ({
|
|||||||
const widthNumber = ((ar / rowAspectRatioSum) * 100).toFixed(7);
|
const widthNumber = ((ar / rowAspectRatioSum) * 100).toFixed(7);
|
||||||
|
|
||||||
const width = `${widthNumber}%`;
|
const width = `${widthNumber}%`;
|
||||||
|
console.log(image.fields.imageMeta.dominantHue);
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
className="border border-black inline-block"
|
className={classNames(
|
||||||
|
"border-4 overflow-hidden",
|
||||||
|
debug && "border-8"
|
||||||
|
)}
|
||||||
id={image.base}
|
id={image.base}
|
||||||
key={`${image.base}`}
|
key={`${image.base}`}
|
||||||
state={{ modal: true }}
|
state={{ modal: true }}
|
||||||
style={{
|
style={{
|
||||||
|
height: `calc(100vw / ${rowAspectRatioSum} - 10px)`,
|
||||||
width,
|
width,
|
||||||
|
// borderColor: `hsl(${image.fields.imageMeta.dominantHue}, 100%, 50%)`
|
||||||
|
// borderColor: `rgb(${image.fields.imageMeta.vibrant.Vibrant.join(',')})`
|
||||||
|
borderColor: debug
|
||||||
|
? `hsl(
|
||||||
|
${image.fields.imageMeta.dominantHue[0]},
|
||||||
|
${image.fields.imageMeta.dominantHue[1] * 100}%,
|
||||||
|
${image.fields.imageMeta.dominantHue[2] * 100}%
|
||||||
|
)`
|
||||||
|
: "black",
|
||||||
}}
|
}}
|
||||||
to={`/photogallery/${image.base}`}
|
to={`/photogallery/${image.base}`}
|
||||||
>
|
>
|
||||||
|
{debug && (
|
||||||
|
<span className="text-white z-20 absolute bg-black">
|
||||||
|
hsl(
|
||||||
|
{image.fields.imageMeta.dominantHue[0]},{' '}
|
||||||
|
{(image.fields.imageMeta.dominantHue[1] * 100).toFixed(2)}%,{' '}
|
||||||
|
{(image.fields.imageMeta.dominantHue[2] * 100).toFixed(2)}% )
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
<GatsbyImage
|
<GatsbyImage
|
||||||
alt={getName(image)}
|
alt={getName(image)}
|
||||||
className="w-full"
|
className="w-full h-full"
|
||||||
image={getImage(image)}
|
image={getImage(image)}
|
||||||
objectFit="cover"
|
objectFit="cover"
|
||||||
/>
|
/>
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
import * as R from "ramda";
|
||||||
import { graphql, Link } from "gatsby";
|
import { graphql, Link } from "gatsby";
|
||||||
import { navigate } from "gatsby";
|
import { navigate } from "gatsby";
|
||||||
import { Helmet } from "react-helmet";
|
import { Helmet } from "react-helmet";
|
||||||
@ -6,9 +7,15 @@ import { Helmet } from "react-helmet";
|
|||||||
import MasonryGallery from "../components/MasonryGallery";
|
import MasonryGallery from "../components/MasonryGallery";
|
||||||
|
|
||||||
const GalleryPage = ({ data }) => {
|
const GalleryPage = ({ data }) => {
|
||||||
|
const [debug, setDebug] = React.useState(false);
|
||||||
|
|
||||||
const images = React.useMemo(
|
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 (
|
return (
|
||||||
@ -39,9 +46,24 @@ const GalleryPage = ({ data }) => {
|
|||||||
</Link>
|
</Link>
|
||||||
</nav>
|
</nav>
|
||||||
<div className="bg-black min-h-screen mx-auto">
|
<div className="bg-black min-h-screen mx-auto">
|
||||||
<h1 className="text-5xl mt-0 ml-5 font-serif font-black z-10 relative">
|
<div className="flex flex-col md:flex-row">
|
||||||
Photo Gallery
|
<h1 className="text-5xl mt-0 ml-5 font-serif font-black z-10 flex-auto">
|
||||||
</h1>
|
Photo Gallery
|
||||||
|
</h1>
|
||||||
|
{window && window.location.hash.includes("debug") ? (
|
||||||
|
<div className="m-2">
|
||||||
|
<label>
|
||||||
|
<input
|
||||||
|
className="mr-1"
|
||||||
|
onChange={() => setDebug(!debug)}
|
||||||
|
type="checkbox"
|
||||||
|
value={debug}
|
||||||
|
/>
|
||||||
|
[debug] use stats.dominant instead of vibrant.Vibrant
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</div>
|
||||||
<div className="mx-auto">
|
<div className="mx-auto">
|
||||||
<MasonryGallery
|
<MasonryGallery
|
||||||
aspectsByBreakpoint={{
|
aspectsByBreakpoint={{
|
||||||
@ -50,6 +72,7 @@ const GalleryPage = ({ data }) => {
|
|||||||
lg: 4,
|
lg: 4,
|
||||||
xl: 5,
|
xl: 5,
|
||||||
}}
|
}}
|
||||||
|
debug={debug}
|
||||||
images={images}
|
images={images}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@ -62,7 +85,7 @@ export const query = graphql`
|
|||||||
query GalleryPageQuery {
|
query GalleryPageQuery {
|
||||||
allFile(
|
allFile(
|
||||||
filter: { sourceInstanceName: { eq: "gallery" } }
|
filter: { sourceInstanceName: { eq: "gallery" } }
|
||||||
sort: { fields: fields___imageMeta___dominantHue, order: DESC }
|
sort: { fields: fields___imageMeta___vibrantHue, order: DESC }
|
||||||
) {
|
) {
|
||||||
edges {
|
edges {
|
||||||
node {
|
node {
|
||||||
@ -85,6 +108,9 @@ export const query = graphql`
|
|||||||
meta {
|
meta {
|
||||||
ObjectName
|
ObjectName
|
||||||
}
|
}
|
||||||
|
vibrant {
|
||||||
|
Vibrant
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user