Skip to content

Commit

Permalink
feat: add all tif metadata tags
Browse files Browse the repository at this point in the history
  • Loading branch information
moonayyur committed Mar 27, 2024
1 parent 7515e5b commit fe30c34
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/hooks/useImageInformations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,29 @@ export default function useImageInformations(image: Image | null) {
components: image.components,
colorModel: image.colorModel,
};
const meta = image.meta?.tiff.tags || {};
const fields = Object.fromEntries(image.meta?.tiff?.fields || []);

for (const [tagCode, tagValue] of Object.entries(fields)) {
if (typeof tagValue === 'string' && tagValue.startsWith('<')) {
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(tagValue, 'text/xml');
const dataNodes = xmlDoc.querySelectorAll('Data');
const fieldInfo: Record<string, unknown> = {};
for (const dataNode of dataNodes) {
const label = dataNode.querySelector('Label')?.textContent;
const value = dataNode.querySelector('Value')?.textContent;
if (label && value) {
fieldInfo[label] = value;
}
}
fields[tagCode] = fieldInfo;
}
}

const meta = {
...image.meta?.tiff?.tags,
...fields,
};
return { info, meta };
}, [image]);
}

0 comments on commit fe30c34

Please sign in to comment.