Published
Edited
Jan 29, 2021
3 stars
Insert cell
Insert cell
viewof input = fileInput({
initialValue: FileAttachment("sample01.jpg").blob(),
accept: ".jpg,.jpeg"
})
Insert cell
depthInfo = getDepthInfo(input)
Insert cell
depthInfo &&
depthInfo.hasDepth &&
html`
<div style="display: grid; grid-gap: .5rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));">
<img src=${URL.createObjectURL(input)} style="width: 100%;" />
<img src=${depthInfo.url} style="width: 100%;" />
</div>
`
Insert cell
getDepthInfo = async function(input) {
const info = await exifr.parse(input, {
// We don't need TIFF, nor thumbnail, so skip this segment (enabled by default).
tiff: false,
// Depth map is stored in an XMP Extended segment (not the main one).
xmp: true,
// We need to tell exifr not to stop at the first XMP segment, but to find them all.
multiSegment: true,
// There will be mutliple XMP namespaces (GDepth, GImage) with the same properties (Mime, Data).
// We don't want them to overwrite each other.
mergeOutput: false
});

if (info && info.GDepth) {
const { Data, Mime } = info.GDepth;
const url = `data:${Mime};base64,${Data}`;
return { hasDepth: true, info, url };
}

return { hasDepth: false };
}
Insert cell
Insert cell
exifr = import('https://unpkg.com/exifr@6.0.0/dist/full.esm.mjs')
Insert cell
import { fileInput } from "@mbostock/file-input-with-initial-value"
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more