• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Get metadata using extendscript from raw file(.cr2,.cr3 etc) without opening the raw file

Community Beginner ,
Jul 30, 2024 Jul 30, 2024

Copy link to clipboard

Copied

This works no problem with a jpeg however the same method doesn't work with a camera raw file.

https://community.adobe.com/t5/photoshop-ecosystem-discussions/get-print-dpi-resolution/m-p/10502704...

I have also tried this but it only shows the first part of the metadata. I really don't know what to do.  Essentially I just want to check if there is a rating greater than 0 in the metatdata of files in a folder without opening/closing each RAW file individually as it takes a lot of time. Any help would be much appreciated.

if (ExternalObject.AdobeXMPScript === undefined) {
    ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
}

// Function to load XMP metadata from raw file
function loadXMPMetadata(rawFilePath) {
    var xmpFile = new File(rawFilePath);
    if (!xmpFile.exists) {
        alert("Raw file does not exist: " + rawFilePath);
        return;
    }

    // Read the XMP data from the file
    xmpFile.open('r');
    var xmpData = xmpFile.read();
    xmpFile.close();
    alert(xmpData)
    // Create an XMPMeta object from the data
    var xmp = new XMPMeta(xmpData);
    var serializedXMP = xmp.serialize()
    alert(serializedXMP)
}

 

TOPICS
Actions and scripting

Views

132

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 31, 2024 Jul 31, 2024

This does it for a folder of CR3 images:

 

/*
Get XMP Rating Metadata for CR3 Files in Folder.jsx
v1.0 - 31st July 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/get-metadata-using-extendscript-from-raw-file-cr2-cr3-etc-without-opening-the-raw-file/td-p/14770220
*/

#target photoshop

if (ExternalObject.AdobeXMPScript === undefined) {
    ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
}

try {
    var theFolder = Folder.selectDialog(
...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 30, 2024 Jul 30, 2024

Copy link to clipboard

Copied

What do you see in File > File Info > Raw Data?

 

Something like this?

 

<tiff:XResolution>300/1</tiff:XResolution>
<tiff:YResolution>300/1</tiff:YResolution>
<tiff:ResolutionUnit>2</tiff:ResolutionUnit>

 

Keep in mind that this isn't coming from the raw file, it is coming from the ACR workflow options.

 

Are there XMP sidecar files for the raw files? These would be faster to process. Edit: It looks like there isn't any useful info in the XMP sidecar file.

 

One could argue that for a raw file, this is meaningless. It may be at a default value such as 72 ppi, or some other value set by the camera or hard-coded by the manufacturer. Different raw file formats may or may not contain this metadata or may contain conflicting metadata.

 

I would probably use ExifTool for this task.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

Thank you so much for responding. I ended up falling asleep here in the EU. I don't think I was clear in my question and I apologise. I wanted to get the metadata of raw file so that I can get the star rating. The side car files only appear after I open the file and do something with it manually. I really need to use photoshop as this code I'm trying to make is part of a larger script with photoshop. It's the only part I haven't got working.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

Ah, the link that you posted was about resolution, I wasn't sure why you used the term "a rating greater than zero".

 

This wouldn't exist in the raw file as Adobe treat that as read-only, it would be in the XMP sidecar file.

 

Are you saying that your camera or some other software that you use upstream has a rating feature that directly rates a raw image outside of Photoshop, Bridge etc – without using a sidecar? If so, can you provide a sample of such as raw file?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

https://filetransfer.io/data-package/BVPcCl0a#link
This is the raw file here. The rating should equal to three stars. It would be ideal if it was possible to do this.
I apologise about that it just showed a way to get the metatdata without opening the file in photoshop. Jpg only though. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

OK, yes, the raw file does have a 3 star rating, so you must have used non-Adobe software to modify the raw.

 

Code here to set the rating on an open doc:

 

https://community.adobe.com/t5/photoshop-ecosystem-discussions/action-rating-5-stars/m-p/13416151

 

Code here to set metadata on files without opening them:

 

 
You will need to use getProperty rather than setProperty... I don't often work with metadata in scripting, I usually use ExifTool as it much more accessible.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 30, 2024 Jul 30, 2024

Copy link to clipboard

Copied

For a CR2 file with no sidecar, Exiftool reports the following:

 

[IFD0]          XResolution                     : 72
[IFD0]          YResolution                     : 72
[IFD0]          ResolutionUnit                  : inches

 

For an ORF file, there is main image info (IFD0) and thumbnail info (IFD1):

 

[IFD0]          XResolution                     : 314
[IFD0]          YResolution                     : 314
[IFD0]          ResolutionUnit                  : inches

[IFD1]          XResolution                     : 72
[IFD1]          YResolution                     : 72
[IFD1]          ResolutionUnit                  : inches

 

For an ARW file, again, there is main image info (IFD0) and thumbnail info (IFD1):

 

[IFD0]          XResolution                     : 350
[IFD0]          YResolution                     : 350
[IFD0]          ResolutionUnit                  : inches

[SubIFD]        XResolution                     : 350
[SubIFD]        YResolution                     : 350
[SubIFD]        ResolutionUnit                  : inches

[IFD1]          XResolution                     : 72
[IFD1]          YResolution                     : 72
[IFD1]          ResolutionUnit                  : inches

 

More here:

 

https://exiftool.org/#groups

 

https://exiftool.org/#tagnames

 

https://exiftool.org/TagNames/

 

https://exiftool.org/TagNames/EXIF.html

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

@Jibbleton 

 

This code does it for a single image, without opening the image:

 

/*
Based on:
https://community.adobe.com/t5/photoshop-ecosystem-discussions/how-to-read-xmp-metadata-in-ps-using-javascript/m-p/12966451
*/

#target photoshop

var theFile = File.openDialog();
var ns = "http://ns.adobe.com/xap/1.0/";
ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
xmpMeta = new XMPFile(theFile.fsName, XMPConst.FILE_XMP, XMPConst.OPEN_FOR_READ).getXMP();
var theValue = Math.abs(xmpMeta.getProperty(ns, "Rating"));
alert("Rating: " + theValue + " stars");

 

You would just need to adapt this to loop over the files in the folder, rather than selecting a single image.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

This does it for a folder of CR3 images:

 

/*
Get XMP Rating Metadata for CR3 Files in Folder.jsx
v1.0 - 31st July 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/get-metadata-using-extendscript-from-raw-file-cr2-cr3-etc-without-opening-the-raw-file/td-p/14770220
*/

#target photoshop

if (ExternalObject.AdobeXMPScript === undefined) {
    ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
}

try {
    var theFolder = Folder.selectDialog("Select a folder...");
    if (theFolder) {
        var files = theFolder.getFiles(function (file) {
            return file instanceof File && /\.cr3$/i.test(file.name);
        });

        if (files && files.length > 0) {
            var theFiles = [];
            for (var i = 0; i < files.length; i++) {
                var theRating = getXMPRating(files[i]);
                theFiles.push(files[i].name + " - Rating: " + theRating);
            }
            alert("Files containing rating metadata:\n" + theFiles.join("\n"));
        } else {
            alert("No supported files found in the selected folder!");
        }
    } else {
        alert("No folder selected!");
    }
} catch (e) {
    alert("An error occurred: " + e.message);
}


function getXMPRating(file) {
    try {
        var xmpFile = new XMPFile(file.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);
        var xmp = xmpFile.getXMP();
        if (xmp.doesPropertyExist(XMPConst.NS_XMP, "Rating")) {
            return xmp.getProperty(XMPConst.NS_XMP, "Rating");
        }
    } catch (e) {
        // If there's an error, return 0 (unrated)
        return 0;
    }
    // Default to 0 if no rating found
    return 0;
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

LATEST

You're welcome!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

Why not use Bridge for this? That way you can read both the RAW file and the XMP sidecar together.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 31, 2024 Jul 31, 2024

Copy link to clipboard

Copied

Building a specific script that runs only in photoshop. I haven't used bridge in years to be honest. Maybe I could have done something with it but it's done now. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines