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

How to extract image dimensions from a PPro projectItem

Adobe Employee ,
Apr 28, 2021 Apr 28, 2021

Hello all! 

Thanks to an interesting question from a PPro scripter, I've written some example PPro ExtendScript that extracts the dimensions of a projectItem. 

 

 

var kPProPrivateProjectMetadataURI	= "http://ns.adobe.com/premierePrivateProjectMetaData/1.0/";

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

var firstItemInProject = app.project.rootItem.children[0];  // make sure first item is media.

if (firstItemInProject) {
    var projectMetadata = firstItemInProject.getProjectMetadata();
	if (projectMetadata) {
		var projectMetadataAsXMP = new XMPMeta(projectMetadata);
		if (projectMetadataAsXMP) {
			var dimensionsFieldName = "Column.Intrinsic.VideoInfo";
			var dimensionsInfo = projectMetadataAsXMP.getProperty(kPProPrivateProjectMetadataURI, dimensionsFieldName);
			if (dimensionsInfo) {
				var widthArray 		= [];
				var heightArray		= [];
				var dimensionsVal 	= dimensionsInfo.value;
				
				var widthEndPos 	= dimensionsVal.indexOf(" ");
				var heightStartPos	= (dimensionsVal.indexOf("x") + 2);
				var heightEndPos 	= dimensionsVal.indexOf("(") - 1;
				
				for (var a = 0; a < widthEndPos; a++) {
					widthArray[a] = dimensionsVal[a];
				}

				for (var b = 0; b < (heightEndPos - heightStartPos); b++) {
					heightArray[b] = dimensionsVal[b + heightStartPos]; // offset to start of height, within source dimension value.
				}

				var widthAsString	= widthArray.join("");	// turn the array into a string, with no separator characters
				var heightAsString	= heightArray.join("");
				
				var width = parseInt(widthAsString);		// turn the string into an int.
				var height = parseInt(heightAsString);

			}
		}
	}
}

 

 

TOPICS
How to , SDK
285
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 ,
Apr 17, 2023 Apr 17, 2023
LATEST

Thanks, exactly what I was looking for!
The last part could be written like this as well (much simpler):

 

 

if (dimensionsInfo) {
  var val  = dimensionsInfo.value;
  var mid = val.indexOf("x");
  var width = parseInt(val.substr(0, mid));
  var height = parseInt(val.substr(mid + 1));
}

 

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