How to extract image dimensions from a PPro projectItem

Adobe Employee ,
Apr 28, 2021 Apr 28, 2021

Copy link to clipboard

Copied

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

Views

39

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
no replies

Have something to add?

Join the conversation