2 Replies Latest reply on Jan 20, 2010 6:38 AM by penyfai

    Get the effective resolution of all images in a doc - JS

    penyfai Level 1

      Hi everyone


      I need to interrogate all images that are placed in an Indesign doc, to ensure that the effective resolution is above 150dpi or 300dpi depending on print quality.


      In applescript I can do it thus:

              set graphiclist to every item of all graphics where item 1 of effective ppi < 150


      Then do anything I need to with the list of images


      I am finding it a whole different prospect in Javascript (which I've got to change to).


      I've tried:

            var mydoc = app.activeDocument;

            var GraphicArray = mydoc.allGraphics;


      but from this point on, everything I've tried doesn't allow me to get the effective reslolution.


      Any help gratefully recieved, Cheers

        • 1. Re: Get the effective resolution of all images in a doc - JS
          Muppet Mark-QAl63s Level 4

          AppleScript's 'whose' n 'where' are shorthand filtering as far as Im aware JavaScript does not have this (A noob so could be wrong?).

          It would equate to make new array loop thru your object array inside of an if condition statement then push to array.


          OK, I had a quick try at this but there are probably better ways of doing this (did work for me with a basic test)


          #target indesign




          function main() {

          if (app.documents.length == 0) {

          alert("Please have an 'Indesign' document before running this script.");



          docRef = app.activeDocument;

          with(docRef) {

          var lowresImages = new Array();

          for (var i = 0; i < allGraphics.length; i++) {

          if (allGraphics[i] instanceof Image) {

          alert('This Graphic is an Image…');

          if (allGraphics[i].effectivePpi[0] < 150 || allGraphics[i].effectivePpi[1] < 150) {

          // Write info to ESTK's JavaScript console

          $.write(allGraphics[i].id + '\n');

          $.write(allGraphics[i].effectivePpi + '\n'); // Array

          // Push what ever you want to Array



          } else {

          alert('This Graphic is not an Image…');







          The lines starting with $.write are just for checking values in ESTK and can be removed.

          • 2. Re: Get the effective resolution of all images in a doc - JS
            penyfai Level 1

            Many thanks Mark.


            Is it time that you didn't consider yourself a noob?


            The reason I took so long to get back, is that I wanted to include some decisions with the effective res, and I really am a noob.


            This is what I've done so far, slightly different to yours but the same theory behind it :


            var adName = app.activeDocument.name;

            var adCID = adName.substring (0, 8);

            var PDFbaseIndd = "/Volumes/ColourPrint/InDesign_PDFs/";

            var PDFbaseCW = "/Volumes/AdvertsForClasswizard/";

            var EPSbase = "/Volumes/Pulse_OPI/PulseInputs/Pulse_Complete/";

            var outputEPSpath = (EPSbase + adCID);

            var ClassWizPDFpath = (PDFbaseCW + adCID + ".pdf");



            //Ask what type the advert is --------------------------------------------------------------------------

            myDlg = new Window('dialog', 'Advert type?');

            myDlg.orientation = 'row';

            // Add action buttons

            myDlg.btn1 = myDlg.add('button', undefined, 'Newsprint');

            myDlg.btn2 = myDlg.add('button', undefined, 'Commercial');



            // Add button functions ---------------------------------------------------------------------------------

            myDlg.btn1.onClick = function() {



            myDlg.btn2.onClick = function() {



            result = myDlg.show();

            if (result == 1) {

            var targetResolution = 150;

            var AdvertType = "newsprint";


            else {

            var targetResolution = 300;

            var AdvertType = "commercial";



            alert("So this is a " + AdvertType + " job at " + targetResolution + " dpi");



            //CHECK ADVERT FOR IMAGES BELOW targetResolution -----------------------------------------------------------------

            var mydoc = app.activeDocument;

            var GraphicArray = mydoc.allGraphics;

            var graphicnumber = GraphicArray.length;

            alert("There are " + graphicnumber + " graphics.\n " + GraphicArray);

            var LowResGraphics = [];

            for (i=0; i<graphicnumber; i++)


            if(GraphicArray[i] instanceof Image)


            if(GraphicArray[i].effectivePpi[0] < targetResolution || GraphicArray[i].effectivePpi[0] < targetResolution)


            var GraphicName = GraphicArray[i].itemLink.filePath;

            alert("Graphic\n" + GraphicName + "\n is under resolution for " + AdvertType);







            Now I should be able to create a report of graphics used that are under resolution and give the user an option to open the images in photoshop to fix them.


            Many thanks again for putting me back on course.