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

Script to add Image Size to Description field to include in Printing Marks

Explorer ,
May 03, 2024 May 03, 2024

Hi all,

Any help appreciated on this. I'm looking for a script that will add this info:

image size.jpg

 

Into the Description field:

image descrip.jpg

 

Allowing it to display in a printout when the Description field is checked in the Printing Marks window:image size print.jpg

 

Thanks!

TOPICS
Actions and scripting
575
Translate
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 , May 03, 2024 May 03, 2024

@TaraRebeka 

 

The following script will do this for a single open/active document.

 

P.S. It's ppi – not dpi, you can change that yourself if you disagree!  :]

 

Legacy:

 

/*
Add Document Dimensions & Resolution to Description Metadata of Open Document.jsx
4th May 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-add-image-size-to-description-field-to-include-in-printing-marks/td-p/14597499
*/

#target photoshop

// Rounded to 1 decimal place
var theDi
...
Translate
Adobe
Community Expert ,
May 03, 2024 May 03, 2024

@TaraRebeka 

 

The following script will do this for a single open/active document.

 

P.S. It's ppi – not dpi, you can change that yourself if you disagree!  :]

 

Legacy:

 

/*
Add Document Dimensions & Resolution to Description Metadata of Open Document.jsx
4th May 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-add-image-size-to-description-field-to-include-in-printing-marks/td-p/14597499
*/

#target photoshop

// Rounded to 1 decimal place
var theDims = Math.round(activeDocument.width.as('in') * 10) / 10 + "in x " + activeDocument.height.as('in').toFixed(1) + "in @" + activeDocument.resolution + "ppi";

activeDocument.info.caption = theDims;

 

Or current:

 

/*
Add Document Dimensions & Resolution to Description Metadata of Open Document.jsx
4th May 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-add-image-size-to-description-field-to-include-in-printing-marks/td-p/14597499
*/

#target photoshop

// Rounded to 1 decimal place
var theDims = Math.round(activeDocument.width.as('in') * 10) / 10 + "in x " + activeDocument.height.as('in').toFixed(1) + "in @" + activeDocument.resolution + "ppi";

if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
xmp.deleteProperty(XMPConst.NS_DC, 'description');
xmp.setProperty(XMPConst.NS_DC, 'description', theDims);
app.activeDocument.xmpMetadata.rawData = xmp.serialize();

 

You could automate this when opening a file using the Script Events Manager:

 

https://prepression.blogspot.com/2021/10/photoshop-script-events-manager.html

 

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

 

 

Translate
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 ,
May 04, 2024 May 04, 2024
quote

P.S. It's ppi – not dpi, you can change that yourself if you disagree!  :]

Alas, there seems to be no real room for disagreement here. 

Translate
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
Explorer ,
May 10, 2024 May 10, 2024

Thanks so much! It worked like a charm.

Translate
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 ,
May 10, 2024 May 10, 2024

@TaraRebeka – You're welcome!

Translate
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
Explorer ,
Aug 26, 2024 Aug 26, 2024

Curious - do you know why this script wouldn't work with Photoshop Elements? I had a coworker who wanted to use and it kicked back this:

 

error.jpg

 

Thanks.

Translate
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 ,
Aug 26, 2024 Aug 26, 2024
LATEST

@TaraRebeka 

 

My natural response is that Photoshop Elements isn't Photoshop.

 

 I don't use Elements so I can't test. That being said, one could try simplifying the code to troubleshoot. Example, replace the original variable with this troubleshooting version which simplifies the previous to only show the resolution:

 

var theDims = activeDocument.resolution + "ppi";

 

If that works, then the width and height could be checked and so on.

 

I also provided an Adobe Bridge version that could alternatively be used.

Translate
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
Explorer ,
May 10, 2024 May 10, 2024

Thanks so much. Worked like a charm!

Translate
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 ,
May 03, 2024 May 03, 2024

Adobe Bridge is better suited to such things than Photoshop IMHO.

 

As I don't normally script Bridge, this hack is a little rougher than I would like (PNG files are not supported).

 

/*
https://community.adobe.com/t5/photoshop-ecosystem-discussions/script-to-add-image-size-to-description-field-to-include-in-printing-marks/td-p/14597499
*/

#target bridge

///// NOTE: PNG files will return the incorrect dimension and resolution values, ignore them!

if (BridgeTalk.appName == "bridge") {
   FT = MenuElement.create("command", "Add Dimensions & Resolution to Description", "at the end of Tools");
}

FT.onSelect = function () {
   //var thumbs = app.document.selections;
   var thumbs = app.document.getSelection('jpg, jpeg, tif, tiff, psd, psb, webp'); // Don't include PNG!
   if (!thumbs.length) return;
   if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject("lib:AdobeXMPScript");
   for (var a in thumbs) {
      var selectedFile = thumbs[a].spec;
      ///// Not for PNG
      var theRes = thumbs[a].core.quickMetadata.xResolution;
      ///// Rounded to 1 decimal place
      var theWidth = (thumbs[a].core.quickMetadata.width / thumbs[a].core.quickMetadata.xResolution).toFixed (1);
      var theHeight = (thumbs[a].core.quickMetadata.height / thumbs[a].core.quickMetadata.xResolution).toFixed (1);
      var theDims = theWidth + "in x " + theHeight + "in @" + theRes + "ppi";
      /////
      var myXmpFile = new XMPFile(selectedFile.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_UPDATE);
      var myXmp = myXmpFile.getXMP();
      var Desc = [];
      var count = myXmp.countArrayItems(XMPConst.NS_DC, "description");
      for (var i = 1; i <= count; i++) {
         Desc.push(myXmp.getArrayItem(XMPConst.NS_DC, "description", i));
      }
      myXmp.deleteProperty(XMPConst.NS_DC, "description");
      myXmp.appendArrayItem(XMPConst.NS_DC, "description", theDims, 0, XMPConst.ALIAS_TO_ALT_TEXT);
      myXmp.setQualifier(XMPConst.NS_DC, "description[1]", "http://www.w3.org/XML/1998/namespace", "lang", "x-default");
      if (myXmpFile.canPutXMP(myXmp)) {
         myXmpFile.putXMP(myXmp);
         myXmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);
      }
   }
}

 

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

Translate
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 ,
May 10, 2024 May 10, 2024

Be aware that Save for Web will strip this out unless you use the All Metadata option. I write product weight into this field using a script, but also write it into the Headline field of my master PSD files. I have a second script that pulls the Headline data and writes it back into Description. That way I don't have to manually reenter the weights on my finished JPEG files.

Translate
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