mirror of
https://github.com/kremalicious/blog.git
synced 2025-02-14 21:10:25 +01:00
exif tweaks
This commit is contained in:
parent
84cbd6109f
commit
752405020a
@ -51,21 +51,49 @@ exports.onCreateNode = ({ node, actions, getNode }) => {
|
|||||||
// exif
|
// exif
|
||||||
if (node.internal.mediaType === 'image/jpeg') {
|
if (node.internal.mediaType === 'image/jpeg') {
|
||||||
fastExif
|
fastExif
|
||||||
.read(node.absolutePath)
|
.read(node.absolutePath, true)
|
||||||
.then(exifData => {
|
.then(exifData => {
|
||||||
|
if (!exifData) return
|
||||||
generateExif(exifData, createNodeField, node)
|
generateExif(exifData, createNodeField, node)
|
||||||
})
|
})
|
||||||
.catch(() => null) // just silently fail when exif can't be extracted
|
.catch(() => null) // just silently fail when exif can't be extracted
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getFraction = decimal => {
|
||||||
|
for (var denominator = 1; (decimal * denominator) % 1 !== 0; denominator++);
|
||||||
|
return { numerator: decimal * denominator, denominator: denominator }
|
||||||
|
}
|
||||||
|
|
||||||
const generateExif = (exifData, createNodeField, node) => {
|
const generateExif = (exifData, createNodeField, node) => {
|
||||||
const iso = exifData.exif.ISO || null
|
const { Model } = exifData.image
|
||||||
const model = exifData.image.Model || null
|
const {
|
||||||
const fstop = exifData.exif.FNumber || null
|
ISO,
|
||||||
const shutterspeed = exifData.exif.ExposureTime || null
|
FNumber,
|
||||||
const focalLength = exifData.exif.FocalLength || null
|
ExposureTime,
|
||||||
const exposure = exifData.exif.ExposureBiasValue || null
|
FocalLength,
|
||||||
|
ExposureBiasValue
|
||||||
|
} = exifData.exif
|
||||||
|
|
||||||
|
const shutterspeedNumerator = getFraction(ExposureTime).numerator
|
||||||
|
const shutterspeedDenominator = getFraction(ExposureTime).denominator
|
||||||
|
const exposureShortened = parseFloat(ExposureBiasValue.toFixed(2))
|
||||||
|
|
||||||
|
const model = Model
|
||||||
|
const iso = `ISO ${ISO}`
|
||||||
|
const fstop = `ƒ ${FNumber}`
|
||||||
|
const shutterspeed = `${shutterspeedNumerator}/${shutterspeedDenominator}s`
|
||||||
|
const focalLength = `${FocalLength}mm`
|
||||||
|
|
||||||
|
let exposure
|
||||||
|
|
||||||
|
if (ExposureBiasValue === 0) {
|
||||||
|
exposure = `+/- ${exposureShortened} ev`
|
||||||
|
} else if (ExposureBiasValue > 0) {
|
||||||
|
exposure = `+ ${exposureShortened} ev`
|
||||||
|
} else {
|
||||||
|
exposure = `${exposureShortened} ev`
|
||||||
|
}
|
||||||
|
|
||||||
// add exif fields to type File
|
// add exif fields to type File
|
||||||
createNodeField({
|
createNodeField({
|
||||||
|
@ -2,65 +2,17 @@ import React from 'react'
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import styles from './Exif.module.scss'
|
import styles from './Exif.module.scss'
|
||||||
|
|
||||||
const getFraction = decimal => {
|
|
||||||
for (var denominator = 1; (decimal * denominator) % 1 !== 0; denominator++);
|
|
||||||
return { numerator: decimal * denominator, denominator: denominator }
|
|
||||||
}
|
|
||||||
|
|
||||||
const ExposureFormatted = ({ exposure }) => {
|
|
||||||
const exposureShortened = exposure.toFixed(0)
|
|
||||||
|
|
||||||
if (exposureShortened === 0) {
|
|
||||||
return `+/- ${exposureShortened}`
|
|
||||||
} else if (exposureShortened > 0) {
|
|
||||||
return `+ ${exposureShortened}`
|
|
||||||
} else {
|
|
||||||
return exposureShortened
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const Exif = ({ exif }) => {
|
const Exif = ({ exif }) => {
|
||||||
const { iso, model, fstop, shutterspeed, focalLength, exposure } = exif
|
const { iso, model, fstop, shutterspeed, focalLength, exposure } = exif
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<aside className={styles.exif}>
|
<aside className={styles.exif}>
|
||||||
{model && (
|
{model && <span title="Camera model">{model}</span>}
|
||||||
<span className="exif__model" title="Camera model">
|
{fstop && <span title="Aperture">{fstop}</span>}
|
||||||
{model}
|
{shutterspeed && <span title="Shutter speed">{shutterspeed}</span>}
|
||||||
</span>
|
{exposure && <span title="Exposure">{exposure}</span>}
|
||||||
)}
|
{iso && <span title="ISO">{iso}</span>}
|
||||||
|
{focalLength && <span title="Focal length">{focalLength}</span>}
|
||||||
{fstop && (
|
|
||||||
<span className="exif__fstop" title="Aperture">
|
|
||||||
{`ƒ ${fstop}`}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{shutterspeed && (
|
|
||||||
<span className="exif__shutterspeed" title="Shutter speed">
|
|
||||||
{`${getFraction(shutterspeed).numerator}/${
|
|
||||||
getFraction(shutterspeed).denominator
|
|
||||||
}s`}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{exposure && (
|
|
||||||
<span className="exif__exposure" title="Exposure">
|
|
||||||
<ExposureFormatted exposure={exposure} />
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{iso && (
|
|
||||||
<span className="exif__iso" title="ISO">
|
|
||||||
{`ISO ${iso}`}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{focalLength && (
|
|
||||||
<span className="exif__focallength" title="Focal length">
|
|
||||||
{`${focalLength}mm`}
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
</aside>
|
</aside>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,32 @@
|
|||||||
@import 'variables';
|
@import 'variables';
|
||||||
|
@import 'mixins';
|
||||||
|
|
||||||
.exif {
|
.exif {
|
||||||
font-size: $font-size-small;
|
font-size: $font-size-mini;
|
||||||
color: $brand-grey-light;
|
color: $brand-grey-light;
|
||||||
margin-top: -($spacer);
|
margin-top: -($spacer * 1.5);
|
||||||
margin-bottom: $spacer * 2;
|
margin-bottom: $spacer * 2;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-wrap: wrap;
|
flex-wrap: wrap;
|
||||||
justify-content: space-between;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
span {
|
span {
|
||||||
flex: 1;
|
display: block;
|
||||||
|
flex: 0 0 33%;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
padding: $spacer / 4;
|
||||||
|
|
||||||
|
&:first-child {
|
||||||
|
flex-basis: 100%;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (min-width: $screen-sm) {
|
||||||
|
span {
|
||||||
|
&,
|
||||||
|
&:first-child {
|
||||||
|
flex: 1 1 auto;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ const Image = ({ fluid, fixed, alt }) => (
|
|||||||
<Img
|
<Img
|
||||||
className={styles.image}
|
className={styles.image}
|
||||||
outerWrapperClassName={styles.imageWrap}
|
outerWrapperClassName={styles.imageWrap}
|
||||||
backgroundColor="#6b7f88"
|
backgroundColor="#dfe8ef"
|
||||||
fluid={fluid ? fluid : null}
|
fluid={fluid ? fluid : null}
|
||||||
fixed={fixed ? fixed : null}
|
fixed={fixed ? fixed : null}
|
||||||
alt={alt}
|
alt={alt}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user