9 Replies Latest reply on Mar 21, 2013 9:02 AM by Trevorׅ

    Actual Image size

    kerosk_inddNew

      Firstly, thanks to Jongware to provide this helpful script.

       

      I have found the script in this from created by Jongware (see link below). Its working fine.

       

      http://forums.adobe.com/message/4329277#4329277

       

      But I require little changes in it.

       

      This script saves a report containing the image name and size.

       

      Can I get the actual image size in pica by this script.

       

      For Example:

       

      Actual image size is 29p0.75 x 11p11.356

       

      Currently script writes the size i.e. 29.1 x 11.9 pt.

       

      Need to modified this so that it gives acutal size in pica i.e., 29p0.75 x 11p11.36.

       

       

      Thanks,

      Kerosk

        • 1. Re: Actual Image size
          Trevorׅ Adobe Community Professional

          see if it helps to change the line

          default: w = w.toFixed(1); h = h.toFixed(1);

          to

          default: w = w.toFixed(3); h = h.toFixed(3);

          • 2. Re: Actual Image size
            Trevorׅ Adobe Community Professional

            Sorry I missread your post, ignore the above answer

            • 3. Re: Actual Image size
              Trevorׅ Adobe Community Professional

              I think this is what you are look for

              (not tested)

              // Changed from Jonware's script
              //  FOR PICAS ONLY !!!!!!!!!!!!!!!
              var hmu = app.activeDocument.viewPreferences.horizontalMeasurementUnits,
                      vmu =  app.activeDocument.viewPreferences.verticalMeasurementUnits;
              app.activeDocument.viewPreferences.horizontalMeasurementUnits = app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.PICAS;        
              res = [];
              imgs = app.activeDocument.allGraphics;
              unitname = "pc";
              for (i=0; i<imgs.length; i++)
              {
                h = imgs[i].parent.geometricBounds[2] - imgs[i].parent.geometricBounds[0];
                w = imgs[i].parent.geometricBounds[3] - imgs[i].parent.geometricBounds[1];
                // some fair rounding
              
                res.push (imgs[i].itemLink.name+'\t'+w+' x '+h+' '+unitname);
              }
              defaultFile = new File (Folder.myDocuments+"/"+app.activeDocument.name.replace(/\.indd$/i, '')+".txt");
              if (File.fs == "Windows")
                writeFile = defaultFile.saveDlg( 'Save report', "Plain text file:*.txt;All files:*.*" );
              else
                writeFile = defaultFile.saveDlg( 'Save report');
              if (writeFile != null)
              {
                if (writeFile.open("w"))
                {
                  writeFile.encoding = "utf8";
                  writeFile.write (res.join("\r")+"\r");
                  writeFile.close();
                }
              }
              app.activeDocument.viewPreferences.horizontalMeasurementUnits = hmu;
              app.activeDocument.viewPreferences.verticalMeasurementUnits = vmu;
              
              • 4. Re: Actual Image size
                kerosk_inddNew Level 1

                Thanks, Trevor for your reply.

                 

                I ran this script but it gives the image size 29.0625 x 11.9463335673014 pc.

                 

                Whereas I needed the actual image size that is 29p0.75 x 11p11.356.

                 

                Help!

                 

                 

                Thanks,

                Kerosk

                • 5. Re: Actual Image size
                  [Jongware] Most Valuable Participant

                  Be warned that what you call "actual image size" is still rounded to *some* degree. As you can see in the value returned by Trevor's script, InDesign is accurate up to 13 or 14 digits, and I doubt you would want to see all of them.

                   

                  Anyway, the problem occurs because picas are not a decimal unit -- they are actually 'duodecimal' (base 12). Using points as the base of measurement, dividing the result by 12, and then showing *only* three significant digits leads to the same display as in InDesign:

                   

                  //DESCRIPTION:Write image size report
                  // A Jongware Script 21-mar-2013
                  var hmu = app.activeDocument.viewPreferences.horizontalMeasurementUnits,
                          vmu =  app.activeDocument.viewPreferences.verticalMeasurementUnits;
                  app.activeDocument.viewPreferences.horizontalMeasurementUnits = app.activeDocument.viewPreferences.verticalMeasurementUnits = MeasurementUnits.POINTS;
                  res = [];
                  imgs = app.activeDocument.allGraphics;
                  unitname = getCurrentUnit();
                  for (i=0; i<imgs.length; i++)
                  {
                    h = imgs[i].parent.geometricBounds[2] - imgs[i].parent.geometricBounds[0];
                    w = imgs[i].parent.geometricBounds[3] - imgs[i].parent.geometricBounds[1];
                    // some required rounding
                    h = ptToPc (h);
                    w = ptToPc (w);
                    res.push (imgs[i].itemLink.name+'\t'+w+' x '+h+' '+unitname);
                  }
                  defaultFile = new File (Folder.myDocuments+"/"+app.activeDocument.name.replace(/\.indd$/i, '')+".txt");
                  if (File.fs == "Windows")
                    writeFile = defaultFile.saveDlg( 'Save report', "Plain text file:*.txt;All files:*.*" );
                  else
                    writeFile = defaultFile.saveDlg( 'Save report');
                  if (writeFile != null)
                  {
                    if (writeFile.open("w"))
                    {
                      writeFile.encoding = "utf8";
                      writeFile.write (res.join("\r")+"\r");
                      writeFile.close();
                    }
                  }
                  app.activeDocument.viewPreferences.horizontalMeasurementUnits = hmu;
                  app.activeDocument.viewPreferences.verticalMeasurementUnits = vmu;
                  function ptToPc (value)
                  {
                    value = Math.round(1000*value);
                    var result = Math.floor(value/12000);
                    var remain = value - 12000*result;
                    if (remain == 0) return String(result)+'p';
                    return String(result)+'p'+String(Math.round(remain)/1000);
                  }
                  
                  • 6. Re: Actual Image size
                    kerosk_inddNew Level 1

                    Thanks a lot, Jongware.

                     

                    This is what I needed. Really appreciate for your time and support.

                     

                    Thanks,

                    Kerosk

                    • 7. Re: Actual Image size
                      Trevorׅ Adobe Community Professional

                      Hi Jongware,

                       

                      you need to change the

                      unitname = getCurrentUnit();

                      to

                      unitname = "pc";

                      as the function doesn't exist any more in the script.

                       

                      Reminds me of a comment I posted not so long ago

                      • 8. Re: Actual Image size
                        [Jongware] Most Valuable Participant

                        That's my own fault ... I use a large "scratch" file for snippets and little scripts such as this. By now it contains almost 700 individual snippets -- 28,000 lines --, and I can usually find a good base to start a new snippet from.

                         

                        In this case, it also contained the *original* version of this script! The entire 'get current unit' stuff is obsolete by now, as it works solely with pica's, but I didn't notice the 'missing' function because JS found it anyway ... 4,100 lines lower!

                        • 9. Re: Actual Image size
                          Trevorׅ Adobe Community Professional

                          Jongware,

                           

                          Any chance of posting that one ?

                           

                          P.s.

                           

                          I had some trouble earlier getting onto the forum,

                          I tried to (and thought I had) post on the original thread http://forums.adobe.com/message/4329277#4329277 a small typo correction on that script.

                          You wrote

                          case MeasurementUnits.PICAS: return "pt";

                          which should have been

                          return "pc";

                          That's what I meant when I wrote

                          "Reminds me of a comment I posted not so long ago "

                           

                          Regards

                           

                          Trevor