ExifReader
ExifReader copied to clipboard
How to get raw exif data?
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?
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.
@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)".
@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
}
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]))));
@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?
[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.
@mattiasw when do I know that I can calculate the values in this way? As far as I know the values in the array could have another meaning, for example they could represent ascii values?
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.
@mattcg could you implement a function that provides this?
I guess you meant to tag me. Maybe one way could be to add the type to the tag object. Would that help you?
@ReedYu What do you mean by the original Exif in this context? The earlier request in this discussion did not describe what I would consider being the original Exif so I want to make sure I understand what you're asking for.
I guess you meant to tag me. Maybe one way could be to add the type to the tag object. Would that help you?
@mattiasw yes. 😉 Now we used exifr, so if you could implement that like in exifr / blueimp we could just replace that libs by ExifReader.
But nevertheless the type could also be helpful, but I'm unsure how we can use it. You mean, we can than know how to calculate the value according to the type? But it seems to me now, this should be a function that the exif reader lib should do.
I want to obtain the original EXIF format and use other plugins to write the original EXIF back to the image. However, I am currently using Piexif-ts to write the EXIF back to the image. Of course, it would be even better if ExifReader could support writing directly.
@ReedYu I'm afraid I still don't understand exactly what you mean. There are several abstraction layers possible here and I don't know how Piexif-ts works. Is it the actual bytes in the file for the whole Exif block? Or the bytes for each specific tag, including size, type, pointer etc? Or a specific representation of the tag value, which is what is being asked for in this thread?
@BuZZ-dEE I think I understand now and it might be a good update. Let's work this through together and see where we land. Can you state all the different types of tags that you think is wrong now and how they should look instead? I think I know the rational numbers, they should just be calculated. What else?
I want to obtain the original EXIF format and use other plugins to write the original EXIF back to the image. However, I am currently using Piexif-ts to write the EXIF back to the image. Of course, it would be even better if ExifReader could support writing directly.我想获取原始的EXIF格式并使用其他插件将原始的EXIF写回图像。不过,我目前正在使用 Piexif-ts 将 EXIF 写回图像。当然,如果ExifReader能够支持直接写入就更好了。
@ReedYu I'm afraid I still don't understand exactly what you mean. There are several abstraction layers possible here and I don't know how Piexif-ts works. Is it the actual bytes in the file for the whole Exif block? Or the bytes for each specific tag, including size, type, pointer etc? Or a specific representation of the tag value, which is what is being asked for in this thread?恐怕我还是不太明白你的意思。这里可能有几个抽象层,我不知道 Piexif-ts 是如何工作的。它是文件中整个 Exif 块的实际字节吗?或者每个特定标签的字节,包括大小、类型、指针等?或者标签值的特定表示,这就是该线程中所要求的?
I apologize for not expressing myself clearly. What I mean is that currently using ExifReader to parse and then using Piexif-ts to write back EXIF has solved my problem. If ExifReader could also implement writing back EXIF, then there would be no need to use another plugin for that, just like discussed in #442
@ReedYu No worries. I see what you mean. As I mentioned in the other discussion I will have a look at it but I can't give a timeline right now.