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

Photoshop Script to Add Missing Resolution Metadata to Exported JPEG Files

Community Expert ,
Nov 10, 2022 Nov 10, 2022

Copy link to clipboard

Copied

I have been tinkering and have the following two scripts to offer to the community. 

 

This may be desired when making use of Photoshop's Export features which are designed to strip irrelevant metadata that is not required for web/device viewing. Some users still wish to have the resolution metadata included, but do not wish to use Save As/Save As a Copy which includes all metadata.

 

I haven't done a lot of metadata scripting, so if there are any inconsistencies please let me know. I have always used ExifTool for this task, wondering why nobody had scripted this before.

 

The first script will add 300 PPI metadata to a single selected JPEG file (the metadata is injected directly into the file without having to open/decompress the image data).

 

The second script will add 300 PPI metadata into all root-level JPEG files in a nominated directory/folder (again, the metadata is injected directly into the file without having to open/decompress the image data).

 

If possible, it would be great if somebody could modify the code to use multiselect = true so that multiple selected files can be processed (I tried but I had issues processing the array of file objects returned).

 

Bridge scripting is the obvious place to do this, however, I started in Photoshop as I am more comfortable there. I'll see if it is possible for me to adapt an existing Bridge script for this purpose.

 

/*
Set the selected JPEG resolution metadata to 300 PPI
v1.0, 10th November 2022, Stephen Marsh
Add the stripped resolution metadata back to exported JPEG files
https://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-script-to-add-missing-resolution-metadata-to-exported-jpeg-files/td-p/13335061
*/

#target photoshop;

var selectFile = app.openDialog();
var selectedFile = File(selectFile);

if (/\.(jpg|jpeg)$/i.test(selectedFile) === true) {
  setResMeta(selectedFile, 300); // Res value in PPI
} else {
  alert("The file isn't a JPEG!")
}


function setResMeta(file, res) {
    if (!ExternalObject.AdobeXMPScript) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
      var xmpFile = new XMPFile(File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
      var xmp = xmpFile.getXMP();

      xmp.setProperty('http://ns.adobe.com/photoshop/1.0/', 'XResolution', res), xmp.rawData = xmp.serialize();
      xmp.setProperty('http://ns.adobe.com/photoshop/1.0/', 'DisplayedUnitsX', 'inches'), xmp.rawData = xmp.serialize();
      xmp.setProperty('http://ns.adobe.com/photoshop/1.0/', 'YResolution', res), xmp.rawData = xmp.serialize();
      xmp.setProperty('http://ns.adobe.com/photoshop/1.0/', 'DisplayedUnitsY', 'inches'), xmp.rawData = xmp.serialize();
      xmp.setProperty('http://ns.adobe.com/tiff/1.0/', 'XResolution', res), xmp.rawData = xmp.serialize();
      xmp.setProperty('http://ns.adobe.com/tiff/1.0/', 'YResolution', res), xmp.rawData = xmp.serialize();
      xmp.setProperty('http://ns.adobe.com/tiff/1.0/', 'ResolutionUnit', 2), xmp.rawData = xmp.serialize();

    if (xmpFile.canPutXMP(xmp)) {
        xmpFile.putXMP(xmp);
    }
    xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}

 

 

/*
Set all JPEG resolution metadata in selected top-level folder to 300 PPI
v1.0, 10th November 2022, Stephen Marsh
Add the stripped resolution metadata back to exported JPEG files
https://community.adobe.com/t5/photoshop-ecosystem-discussions/photoshop-script-to-add-missing-resolution-metadata-to-exported-jpeg-files/td-p/13335061
*/

#target photoshop;

var inputFolder = Folder.selectDialog ("Please select folder to process");
if(inputFolder !== null){
  var fileList = inputFolder.getFiles(/\.(jpg|jpeg)$/i);

  for (var a in fileList) {
    setResMeta(fileList[a], 300); // Res value in PPI
  }
}

function setResMeta(file, res) {
    if (!ExternalObject.AdobeXMPScript) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
      var xmpFile = new XMPFile(File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
      var xmp = xmpFile.getXMP();

      xmp.setProperty('http://ns.adobe.com/photoshop/1.0/', 'XResolution', res), xmp.rawData = xmp.serialize();
      xmp.setProperty('http://ns.adobe.com/photoshop/1.0/', 'DisplayedUnitsX', 'inches'), xmp.rawData = xmp.serialize();
      xmp.setProperty('http://ns.adobe.com/photoshop/1.0/', 'YResolution', res), xmp.rawData = xmp.serialize();
      xmp.setProperty('http://ns.adobe.com/photoshop/1.0/', 'DisplayedUnitsY', 'inches'), xmp.rawData = xmp.serialize();
      xmp.setProperty('http://ns.adobe.com/tiff/1.0/', 'XResolution', res), xmp.rawData = xmp.serialize();
      xmp.setProperty('http://ns.adobe.com/tiff/1.0/', 'YResolution', res), xmp.rawData = xmp.serialize();
      xmp.setProperty('http://ns.adobe.com/tiff/1.0/', 'ResolutionUnit', 2), xmp.rawData = xmp.serialize();

    if (xmpFile.canPutXMP(xmp)) {
        xmpFile.putXMP(xmp);
    }
    xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

TOPICS
Actions and scripting

Views

236

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
community guidelines
Community Expert ,
Nov 19, 2022 Nov 19, 2022

Copy link to clipboard

Copied

LATEST

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
community guidelines