Highlighted

Script to remove all meta data from the photo

New Here ,
Mar 14, 2019

Copy link to clipboard

Copied

Hi

I am looking for a Script to remove all meta data from the photo (main issue is camera and lens info)

if i give my  client a flat image with no layers, i can do it while i export from lightroom.

but i want a way to do it while i keep the layers

is there a photoshop script to do that?

Thank you in advance

Topics

Actions and scripting

Views

3.6K

Likes

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

Script to remove all meta data from the photo

New Here ,
Mar 14, 2019

Copy link to clipboard

Copied

Hi

I am looking for a Script to remove all meta data from the photo (main issue is camera and lens info)

if i give my  client a flat image with no layers, i can do it while i export from lightroom.

but i want a way to do it while i keep the layers

is there a photoshop script to do that?

Thank you in advance

Topics

Actions and scripting

Views

3.6K

Likes

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
Most Valuable Participant ,
Mar 14, 2019

Copy link to clipboard

Copied

Save for web can strip metadata like that.  Adobe Photoshop scripting may treat EXIF  metadata as read only. I never tried to change any Camera metadata its easy to strip.  I think I may have tried to change some EXIF Date taken information one ti,e because the date was set wrong in my Camera. I believe I was not able to or I found an EXIF utility that could change the date a relative number of days so I did not have to script that. The Script I have that process EXIF metadata only read the data. I found lens information was in Adobe Aux metadata I believe the was create by ACR use RAW Files camera maker metadata, the Actual lens was not in EXIF data just the focal length used was. Save For web can strip all metadata or preserve some metadata like copyright information.

JJMack

Likes

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
Reply
Loading...
Guide ,
Mar 14, 2019

Copy link to clipboard

Copied

#target photoshop

removeXMP();

function removeXMP(){

if(!documents.length) return;

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

var xmp = new XMPMeta( activeDocument.xmpMetadata.rawData);

XMPUtils.removeProperties(xmp, "", "", XMPConst.REMOVE_ALL_PROPERTIES);

app.activeDocument.xmpMetadata.rawData = xmp.serialize();

}

Likes

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
Reply
Loading...
Most Valuable Participant ,
Mar 14, 2019

Copy link to clipboard

Copied

I believe after you strip the metadata you still need to save over the original file to remove it from the files. If you want to strip it from the raw files you man need to use the bridge or some utility  application to strip metadata from raw files.   I do not use LR so I do not know what it can do or if it supports scripting.

With Photoshop and his script you could set up an open event handler to strip meda.

JJMack

Likes

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
Reply
Loading...
Adobe Community Professional ,
Mar 14, 2019

Copy link to clipboard

Copied

Hi SuperMerlin,

 

I tested with a layered PSD from a raw camera file and your script appears to only remove XMP metadata, whereas mo54891077​ is looking to remove “all” metadata, but most importantly EXIF/Camera related metadata. There are a couple of key metadata groups that remain, such as IFD0/TIFF (camera make/model info) and EXIF (camera settings info).

 

You know me well enough by now to expect that I am going to post an ExifTool command to perform this task. The following command strips most of the metadata without breaking the file (including camera make, model and settings):

 

exiftool -all= -CommonIFD0= --icc_profile:all 'full path to file'

 

This ExifTool command line code can “easily” be added to a drag-n-drop icon or other system level automation on either Mac or Windows, without ongoing need to use the CLI and code.

 

(This command is for the Mac OS, Windows would use double straight quote marks around the path to the file)

 

I would not recommend that any metadata is stripped from original camera files and that this is only performed on outgoing copies of the originals.

Likes

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
Reply
Loading...
Adobe Community Professional ,
Mar 14, 2019

Copy link to clipboard

Copied

I would like to offer a different brute force approach to removing non-XMP metadata such as EXIF – which is to “rebuild” a copy of the original layered file without metadata. This is performed by duplicating the layers to a new file. NOTE: Paths, alpha channels, guides, colour samplers and other objects will not carry over to the new file (which may be a good thing if this is for a client, they usually don’t require your intermediate “workings”, you are just supplying a layered file if that is the requirement over a flattened file).

 

This can (mostly) be performed using an action and with conditional actions it can gracefully handle a flattened file. The caveat is that if the bottom layer is a group/set then it has to be manually expanded otherwise the contents will not be selected. This is not a major issue in this case, as the sublayers will still be copied to the new file from the selected group/set (download link):

 

refined.png

 

Note, I have used “relative” keyboard shortcuts to navigate and select the layers rather than “absolute” recordings.

 

And here is the “final” scripted version which offers more possibilities than the action method:

 

EDIT: 25th March 2019 – Revised code as the original code for selecting all layers was not “bullet proof”, I hope that this revised code is now robust for various layered file builds (it is known to fail on a flattened image, I have now accounted for that in the error checking code as the script will now process both layered and flattened files):

 

EDIT: 24th April 2020 – Cleaned the previous code removing minor errors in variables, syntax etc:

 

/* Remove All Metadata & Retain Layers - a brute force alternative to ExifTool
https://community.adobe.com/t5/photoshop/script-to-remove-all-meta-data-from-the-photo/m-p/10400906
Script to remove all meta data from the photo */

#target photoshop

// Error check and run on layered files  
// https://forums.adobe.com/thread/2586379 - r-bin  
var originalDoc = app.activeDocument;

var ok = true;

var background_present = true;
try {
    originalDoc.backgroundLayer;
} catch (e) {
    background_present = false;
}

// Doc only has Background layer
if (background_present && originalDoc.artLayers.length === 1 && originalDoc.layerSets.length === 0) ok = false;

// Doc has only 1 layer (optional, uncomment the line below if required)
// if (!background_present && originalDoc.artLayers.length == 1 && originalDoc.layerSets.length == 0) ok = false;

if (ok) {

    // Park the error checking and run the main script  

    // Expand all layer sets
    openAllLayerSets(app.activeDocument);

    // Select all layers and layer groups/sets!
    selectAllLayers();

    // Call function to duplicate all layers
    DupeSelectedLayers.main = function () {
        DupeSelectedLayers();
    };

    DupeSelectedLayers.main();

    // Deselect layers  
    // https://forums.adobe.com/message/5204655#5204655 - Michael L Hale  
    app.runMenuItem(stringIDToTypeID('selectNoLayers'));

    // Collapse all layer groups/sets
    app.runMenuItem(stringIDToTypeID('collapseAllGroupsEvent'));

    /////////////////////////////////////////////////////////////////////////

    // Run on flattened files
} else {

    var origDoc = app.activeDocument;

    // Call function to duplicate all layers
    DupeSelectedLayers.main = function () {
        DupeSelectedLayers();
    };

    DupeSelectedLayers.main();

}

alert('File duplicated to remove metadata with "_NoMetadata" suffix added to the filename for safety.' + '\r' + 'Note: guides, color samplers, alpha channels, paths and other common document additions have not been copied.');

///// FUNCTIONS /////

function openAllLayerSets(parent) {
    // https://forums.adobe.com/message/5764024#5764024
    for (var setIndex = 0; setIndex < parent.layerSets.length; setIndex++) {
        app.activeDocument.activeLayer = parent.layerSets[setIndex].layers[0];
        openAllLayerSets(parent.layerSets[setIndex]);
    }
}

function selectAllLayers() {
    // https://feedback.photoshop.com/photoshop_family/topics/i-cant-record-sellect-all-layers-in-script-listener-and-in-actions
    var c2t = function (s) {
        return app.charIDToTypeID(s);
    };

    var s2t = function (s) {
        return app.stringIDToTypeID(s);
    };

    var descriptor = new ActionDescriptor();
    var descriptor2 = new ActionDescriptor();
    var reference = new ActionReference();
    var reference2 = new ActionReference();

    reference2.putEnumerated(s2t("layer"), s2t("ordinal"), s2t("targetEnum"));
    descriptor.putReference(c2t("null"), reference2);
    executeAction(s2t("selectAllLayers"), descriptor, DialogModes.NO);
    reference.putProperty(s2t("layer"), s2t("background"));
    descriptor2.putReference(c2t("null"), reference);
    descriptor2.putEnumerated(s2t("selectionModifier"), s2t("selectionModifierType"), s2t("addToSelection"));
    descriptor2.putBoolean(s2t("makeVisible"), false);
    try {
        executeAction(s2t("select"), descriptor2, DialogModes.NO);
    } catch (e) { }
}

// Duplicate all selected layers to new document  
function DupeSelectedLayers() {

    function step1(enabled, withDialog) {
        if (enabled !== undefined && !enabled)
            return;
        cTID = function (s) {
            return app.charIDToTypeID(s);
        };
        sTID = function (s) {
            return app.stringIDToTypeID(s);
        };
        var origFilename = app.activeDocument.name.replace(/\.[^\.]+$/, ''); // Remove filename extension from original
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putClass(cTID('Dcmn'));
        desc1.putReference(cTID('null'), ref1);
        desc1.putString(cTID('Nm  '), origFilename + "_NoMetadata"); // Use the original document filename + sufix
        // desc1.putString(cTID('Nm  '), origFilename ); // Use the original document filename, beware overwriting the original file and losing all metadata!              
        var ref2 = new ActionReference();
        ref2.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('Usng'), ref2);
        desc1.putInteger(cTID('Vrsn'), 5);
        executeAction(cTID('Mk  '), desc1, dialogMode);
    }

    step1();
}

///// FUNCTIONS /////

 

Prepression: Downloading and Installing Adobe Scripts

Likes

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
Reply
Loading...
Adobe Community Professional ,
Apr 09, 2019

Copy link to clipboard

Copied

mo54891077 I’m curious, has your issue been resolved, is there any feedback etc? If resolved, can you mark the appropriate answer as correct so that others with the same issue know of the fix?

Likes

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
Reply
Loading...
Adobe Community Professional ,
Jul 15, 2020

Copy link to clipboard

Copied

I thought that the script that I cobbled together from various sources was "bullet-proof", however, I have just found a flaw.

 

Using the Layer > Duplicate Layer feature to move layer content to a new file to avoid copying common file related metadata works fine for a flattened or multi-layered file... I just tested again and a single layer file has issues, whether using the GUI or a script!

 

If the layer is a single layer, it is flattened when duplicated to a new file. This is not too much of a problem if the original layer did not have any canvas transparency, however, I'd like to retain transparency and layer content positioning to the original image/canvas.

 

It is possible to add a temp blank layer to such a single layer file and then select all layers and dupe, however I would then need to remove the temp from both the new file and the original. Surely there is a better way?

 

Can anybody offer code and or advice?

Likes

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
Reply
Loading...
Adobe Community Professional ,
Jul 16, 2020

Copy link to clipboard

Copied

1. select all layers

2. make group

3. duplicate to new doc

3. switch to new doc

4. ungroup or remove group

 

It is alleged that this bug is fixed in 21.2.

https://feedback.photoshop.com/photoshop_family/topics/bug-when-duplicating-layer-to-new-doc-ps21-1-...
I did not check due to the lack of 21.2.

Likes

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
Reply
Loading...
Adobe Community Professional ,
Jul 20, 2020

Copy link to clipboard

Copied

Thanks, so pretty much the same hack as adding a new blank layer to force the dupe to work correctly. I was hoping for something magic! :]

 

I have it sorted now, thanks r-bin...

 

Now I have discovered a different issue to fix!

Likes

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
Reply
Loading...