Get document Exif info

Does anyone know how to get an object containing the Exif info of the active document?
In ExtendScript this would have been “app.activeDocument.info.exif”

I’ve been playing with Alchemist and can get the “fileInfo” object but this only contains keywords and author information, nothing to do with the camera.

So far the only option has been to try and extract it from the raw XMP metadata but that comes with its own set of issues. Thanks for any help :slight_smile:

In case anyone finds it helpful here is how to get the fileInfo object:

var documentFileInfo = await getDocumentFileInfo();
console.log(documentFileInfo);

async function getDocumentFileInfo(){
    const result = await require("photoshop").action.batchPlay(
      [
         {
            "_obj": "get",
            "_target": [
               {
                  "_property": "fileInfo"
               },
               {
                  "_ref": "document",
                  "_enum": "ordinal",
                  "_value": "targetEnum"
               }
            ],
            "_options": {
               "dialogOptions": "dontDisplay"
            }
         }
      ],{
         "synchronousExecution": false,
         "modalBehavior": "fail"
      }); 
      return result;   
   }

You might want to try this:

// Get current opened doc EXIF (String)
var batchPlay = require("photoshop").action.batchPlay;

var get_EXIF = await batchPlay(
   [{
      "_obj": "get",
      "_target": [{
            "_property": "EXIF"
         },
         {
            "_ref": "document",
            "_enum": "ordinal",
            "_value": "targetEnum"
         }
      ]
   }], {});

var data = get_EXIF[0].EXIF;
console.log(data);

Hope this helps :slight_smile:

Hi.

can anyone help to seperate this informations?
if I use
let test = data.split("EXIF-Tag ")
it is not so easy because
test[28]
is not always the same information.

Thanks for your help

Hey Carsten, I had a similar problem when making ProStacker. The solution I found was to create an object using the data.split method you posted and then get the EXIF value I wanted by referencing the key from the object.

Since I needed to display the EXIF field as its normal name (instead of “137386”), I also had to replace many of the strings in the EXIF info before making the object. Someone probably knows a smarter way of doing that…

Here’s the code I used, hope it helps:
(Apologies @Pierre_G for forgetting to mark your answer as solution, thanks for the help)

  // Get current opened doc EXIF (String)
  const get_EXIF = await require("photoshop").action.batchPlay(
    [{
      "_obj": "get",
      "_target": [{
        "_property": "EXIF"
      },
      {
        "_ref": "document",
        "_enum": "ordinal",
        "_value": "targetEnum"
      }
      ]
    }], {});

  const data = get_EXIF[0].EXIF;

  const mapObj = {
    100000: "GPS Version ID :",
    100001: "GPS Latitude Ref :",
    100002: "GPS Latitude :",
    100003: "GPS Longitude Ref :",
    100004: "GPS Longitude :",
    100005: "GPS Altitude Ref :",
    100006: "GPS Altitude :",
    100007: "GPS Time Stamp :",
    100011: "GPS Img Direction :",
    100012: "GPS Speed Ref :",
    100013: "GPS Speed :",
    100016: "GPS Img Direction Ref :",
    100017: "GPS Img Direction :",
    100023: "GPS Dest Bearing Ref :",
    100024: "GPS Dest Bearing :",
    100029: "GPS Version ID Number :",
    100031: "Unknown :",
    100256: "Image Width :",
    100257: "Image Length :",
    100258: "Bits Per Sample :",
    100262: "Photometric Interpretation :",
    100270: "Image Description :",
    100271: "Make :",
    100272: "Model :",
    100274: "Orientation :",
    100277: "Samples Per Pixel :",
    100282: "X Resolution :",
    100283: "Y Resolution :",
    100296: "Resolution Unit :",
    100305: "Software :",
    100306: "Date Time :",
    100315: "Artist :",
    100322: "Tile Width :",
    100323: "Tile Length :",
    104097: "Related Image Width :",
    104098: "Related Image Length :",
    100530: "YCbCr YCbCr Sub Sampling :",
    100531: "YCbCr Positioning :",
    133432: "Copyright :",
    133434: "Exposure Time :",
    133437: "F Number :",
    134850: "Exposure Program :",
    134855: "ISO Speed Ratings :",
    134864: "Sensitivity Type :",
    134865: "Standard Output Sensitivity :",
    134866: "Recommended Exposure Index :",
    136864: "Exif Version :",
    136867: "Date Time Original :",
    136868: "Date Time Digitized :",
    136880: "Offset Time :",
    136881: "Offset Time Original :",
    136882: "Offset Time Digitized :",
    137121: "Components Configuration :",
    137122: "Compressed Bits Per Pixel :",
    137377: "Shutter Speed Value :",
    137378: "Aperture Value :",
    137379: "Brightness Value :",
    137380: "Exposure Bias Value :",
    137381: "Max Aperture Value :",
    137383: "Metering Mode :",
    137384: "Light Source :",
    137385: "Flash :",
    137386: "Focal Length :",
    137396: "Subject Area :",
    137510: "User Comment :",
    137520: "SubSec Time :",
    137521: "SubSec Time Original :",
    137522: "SubSec Time Digitized :",
    140960: "Flashpix Version :",
    140961: "Color Space :",
    140962: "Pixel X Dimension :",
    140963: "Pixel Y Dimension :",
    141486: "Focal Plane X Resolution :",
    141487: "Focal Plane Y Resolution :",
    141488: "Focal Plane Resolution Unit :",
    141495: "Sensing Method :",
    141728: "File Source :",
    141729: "Scene Type :",
    141730: "CFA Pattern :",
    141985: "Custom Rendered :",
    141986: "Exposure Mode :",
    141987: "White Balance :",
    141988: "Digital Zoom Ratio :",
    141989: "Focal Length In 35mm Film :",
    141990: "Scene Capture Type :",
    141991: "Gain Control :",
    141992: "Contrast :",
    141993: "Saturation :",
    141994: "Sharpness :",
    141995: "Device Setting Description :",
    141996: "Subject Distance Range :",
    142016: "Image Unique ID :",
    142033: "Body Serial Number :",
    142034: "Lens Specification :",
    142035: "Lens Make :",
    142036: "Lens Model :"

  };

  // Replace EXIF codes with strings from above
  const re = new RegExp(Object.keys(mapObj).join("|"), "gi");
  const dataClean = data.replace(re, function (matched) {
    return mapObj[matched];
  });

  const exifArray = dataClean.split("EXIF tag ");

  // Tidy up junk at start and end
  exifArray.shift();
  exifArray.pop();

  const metadataObject = {};

  for (let i = 0; i < exifArray.length; i++) {
    metadataObject[exifArray[i].split(" : ")[0]] = decodeURI(exifArray[i].split(" : ")[1]);
  }

console.log(metadataObject["Focal Length"])
2 Likes

Thanks.
On my pc it has to be:
const exifArray = dataClean.split("EXIF-Tag ");

not:
const exifArray = dataClean.split("EXIF tag ");

Thanks a million for sharing this @grebesoft_ben !

I have pilfered some of this for use in my own plugin. Note that the final item in the list, Lens Model, was not being picked up, probably due to the split logic, so I added "EXIF tag " to the data on import, and this seems to work:

const data = get_EXIF[0].EXIF + "EXIF tag "

There’s probably a way to change the logic to avoid this, but the above is a quick and easy workaround if anyone else intends to use this.