Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get raw exif data? #330

Open
BuZZ-dEE opened this issue May 30, 2024 · 10 comments
Open

How to get raw exif data? #330

BuZZ-dEE opened this issue May 30, 2024 · 10 comments

Comments

@BuZZ-dEE
Copy link

BuZZ-dEE commented May 30, 2024

How can I get the raw exif data from the image file in the format like the following?:

{
   271: "Apple",
   272: "iPhone XS",
   274: 1,
   282: 72,
   283: 72,
   …
}

Is that possible?

@mattiasw
Copy link
Owner

Hi! You can get the "raw"/not parsed value of a tag by reading value. If that is what you mean. The tag ID is not available though.

@BuZZ-dEE
Copy link
Author

@mattiasw I need all exif values and each exif value I need to get the by the property "Tag (dec)", because the backend reads the exif values by the "Tag (dec)".

@BuZZ-dEE
Copy link
Author

BuZZ-dEE commented May 30, 2024

@mattiasw For example: https://mutiny.cz/exifr

const exifrData = exifr.parse(fileBuffer, {exif: true, reviveValues: false, translateKeys: false, translateValues: false}).then((values) => {
  console.log('exifr', values);
});

Result:

{
  "0": <Uint8Array 02 02 00 00>,
  "1": "N",
  "2": [50, 17, 58.57],
  "3": "E",
  "4": [14, 49, 13.06],
  "5": <Uint8Array 00>,
  "6": 252,
  "7": [14, 34, 23],
  "11": 18,
  "27": <Uint8Array 41 53 43 49 49 00 00 00 66 75 73 65 64>,
  "29": "2018:07:25",
  "256": 4048,
  "257": 3036,
  "271": "Google",
  "272": "Pixel",
  "274": 1,
  "282": 72,
  "283": 72,
  "296": 2,
  "305": "HDR+ 1.0.199571065z",
  "306": "2018:07:25 16:34:23",
  "531": 1,
  "33434": 0.000376,
  "33437": 2,
  "34665": 239,
  "34850": 2,
  "34853": 18478,
  "34855": 50,
  "36864": <Uint8Array 30 32 32 30>,
  "36867": "2018:07:25 16:34:23",
  "36868": "2018:07:25 16:34:23",
  "37121": <Uint8Array 01 02 03 00>,
  "37377": 11.38,
  "37378": 2,
  "37379": 9.38,
  "37380": 0,
  "37381": 2,
  "37382": 0.892,
  "37383": 2,
  "37385": 16,
  "37386": 4.67,
  "37520": "935476",
  "37521": "935476",
  "37522": "935476",
  "40960": <Uint8Array 30 31 30 30>,
  "40961": 1,
  "40962": 4048,
  "40963": 3036,
  "40965": 18448,
  "41495": 2,
  "41729": 1,
  "41985": 1,
  "41986": 0,
  "41987": 0,
  "41988": 0,
  "41989": 26,
  "41990": 0,
  "41992": 0,
  "41993": 0,
  "41994": 0,
  "41996": 1,
  "latitude": 50.29960277777778,
  "longitude": 14.820294444444444
}

@mattiasw
Copy link
Owner

mattiasw commented May 30, 2024

There is (currently) no parameter to pass in for that but it can be done afterwards. Here is a oneliner that also fixes that strings in their raw format comes in an array. You may want to split this up for better readability. :-)

const tags = await ExifReader.load('/path/to/image.jpg', {expanded: true});
console.log(Object.fromEntries(Object.entries(tags.exif).map(([key, value]) => ([value.id, Array.isArray(value.value) && value.value.length === 1 && typeof value.value[0] === 'string' ? value.value[0] : value.value]))));

@BuZZ-dEE
Copy link
Author

BuZZ-dEE commented May 31, 2024

@mattiasw we already tried that, but we get not the result we need.:

{
  "1": "N",
  "2": [
    [53, 1],
    [15, 1],
    [4194, 100]
  ],
  "3": "E",
  "4": [
    [7, 1],
    [55, 1],
    [3645, 100]
  ],
  "5": 0,
  "6": [47629, 5606],
  "7": [
    [9, 1],
    [56, 1],
    [5326, 100]
  ],
  "12": "K",
  "13": [0, 1],
  "16": "T",
  "17": [366457, 2469],
  "23": "T",
  "24": [366457, 2469],
  "29": "2024:05:30",
  "31": [53285, 6253],
  "271": "Apple",
  "272": "iPhone 13 mini",
  "274": 6,
  "282": [72, 1],
  "283": [72, 1],
  "296": 2,
  "305": "17.4.1",
  "306": "2024:05:30 11:56:59",
  "316": "iPhone 13 mini",
  "33434": [1, 50],
  "33437": [8, 5],
  "34665": 228,
  "34850": 2,
  "34853": 2542,
  "34855": 160,
  "36864": [48, 50, 51, 50],
  "36867": "2024:05:30 11:56:59",
  "36868": "2024:05:30 11:56:59",
  "36880": "+02:00",
  "36881": "+02:00",
  "36882": "+02:00",
  "37377": [50493, 8947],
  "37378": [14447, 10653],
  "37379": [36931, 18383],
  "37380": [0, 1],
  "37383": 5,
  "37385": 16,
  "37386": [51, 10],
  "37396": [1968, 1487, 2320, 1324],
  "37521": "070",
  "37522": "070",
  "40961": 65535,
  "40962": 4032,
  "40963": 3024,
  "41495": 2,
  "41729": 1,
  "41986": 0,
  "41987": 0,
  "41988": [3024, 593],
  "41989": 130,
  "42034": [
    [807365, 524263],
    [51, 10],
    [8, 5],
    [12, 5]
  ],
  "42035": "Apple",
  "42036": "iPhone 13 mini back dual wide camera 5.1mm f/1.6",
  "42080": 2
}

The problem for example is:

"282": [72, 1],

we need the computed value like it is in exifr and blueimp/JavaScript-Load-Image:

282: 72,

Is that possible?

@mattiasw
Copy link
Owner

[72, 1] is a very close representation of the raw data from the file. It's a rational number which is represented by numerator and denominator. So to get the actual number you can divide the first one with the second one. In this case that is 72 since the denominator happens to be 1.

@BuZZ-dEE
Copy link
Author

@mattiasw when do I know that I can calculate the values in this way? As far as I know the values could in the array could have another meaning, for example they could represent ascii values?

@mattiasw
Copy link
Owner

Yeah, it's tricky I'm afraid. In ExifReader there is only the original representation or the computed value as in description, nothing in between where only some tag values are transformed. I guess the back end knows the tag types? Maybe that would be required, to change that too.

@BuZZ-dEE
Copy link
Author

BuZZ-dEE commented Jun 4, 2024

@mattcg could you implement a function that provides this?

@mattiasw
Copy link
Owner

mattiasw commented Jun 9, 2024

I guess you meant to tag me. Maybe one way could be to add the type to the tag object. Would that help you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants