Skip to main content
JJMack
Community Expert
Community Expert
June 1, 2019
Answered

Get Print DPI Resolution?

  • June 1, 2019
  • 1 reply
  • 1260 views

In Windows File explorer I can right click on an image file and click on properties. In the Properties window details tab in the image section see the Images Print resolution setting.  Is there any way with javascript  to get this Print DPI resolution without opening the image file in Photoshop?

This topic has been closed for replies.
Correct answer SuperMerlin

#target photoshop;

main();

function main(){

var file = File.openDialog("Please select JPG file.","JPG File:*.jpg");

if (file == null) return;

if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

        var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ );

        var xmp = xmpf.getXMP();

        if(xmp.doesPropertyExist(XMPConst.NS_TIFF, "XResolution")){

        var res = xmp.getProperty(XMPConst.NS_TIFF, "XResolution");

        res = res.toString().split("/");

        alert(res[0]/res[1]);

        }else{

            alert("No resolution, default 72ppi");

            }

};

1 reply

SuperMerlin
SuperMerlinCorrect answer
Inspiring
June 1, 2019

#target photoshop;

main();

function main(){

var file = File.openDialog("Please select JPG file.","JPG File:*.jpg");

if (file == null) return;

if ( !ExternalObject.AdobeXMPScript ) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

        var xmpf = new XMPFile( File(file).fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ );

        var xmp = xmpf.getXMP();

        if(xmp.doesPropertyExist(XMPConst.NS_TIFF, "XResolution")){

        var res = xmp.getProperty(XMPConst.NS_TIFF, "XResolution");

        res = res.toString().split("/");

        alert(res[0]/res[1]);

        }else{

            alert("No resolution, default 72ppi");

            }

};

JJMack
Community Expert
JJMackCommunity ExpertAuthor
Community Expert
June 2, 2019

Thank You

JJMack