Created
January 17, 2023 17:50
-
-
Save tusamni/529c0777ee790f134751072584e09f96 to your computer and use it in GitHub Desktop.
A snippet to extract EXIF and IPTC data for an image function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// return array with image data | |
export async function getImage(image) { | |
const pathname = `${path.dirname(image)}/${path.parse(image).name}`; | |
const extension = path.parse(image).ext; | |
const source = `${imageConfig.cloudUrl}${pathname}${extension}`; // final image source | |
let metadata = await exifReader.load(source, { length: 128 * 1024 }); | |
if (typeof metadata["Object Name"] === "undefined" || metadata["Object Name"] === null) { | |
return { | |
src: source, | |
width: metadata["Image Width"].value, | |
height: metadata["Image Height"].value, | |
aspectRatio: metadata["Image Width"].value / metadata["Image Height"].value, | |
}; | |
} else { | |
return { | |
src: source, | |
width: metadata["Image Width"].value, | |
height: metadata["Image Height"].value, | |
aspectRatio: metadata["Image Width"].value / metadata["Image Height"].value, | |
title: metadata["Object Name"].description, | |
description: metadata["Caption/Abstract"].description, | |
date: metadata["CreateDate"].value, | |
cameraMake: metadata["Make"].value, | |
cameraModel: metadata["Model"].value, | |
lens: metadata["LensModel"].value, | |
settingsfStop: metadata["ApertureValue"].description, | |
settingsISO: metadata["ISOSpeedRatings"].description, | |
settingsExposure: metadata["ExposureTime"].description, | |
settingsFocalLength: metadata["FocalLength"].value[0] / metadata["FocalLength"].value[1], | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment