15 Replies Latest reply on May 22, 2014 9:49 AM by 喜狼_edny

    what is wrong?  with ID script ,auto change image size use photoshop?

    喜狼_edny Level 1

      I get this scrip from somebody,It is used to auto get the imagesize in Indesign,Open in ps.

      here the image size is touch with  "Direct Selection Tool",then we see the ture width.

       

      but,here, I would like to get the “”true width +12mm“”,

      the bug is coming,some time It is right.the size is right.

      but some times,the size is small, It is not I need, not I hope。

       

      Can you help me ?  (the script is under,save to js,please, the soft is ID CS6)

      My E-mail:57400673@qq.com

      Thank you very much



      -------------------------------------------------------------------------------

      Main();

      function Main() {

                var image = app.selection[0].images[0];

                var imagePath = image.itemLink.filePath;

                var hScale = image.horizontalScale;

                var vScale = image.verticalScale;

                CreateBridgeTalkMessage();

       

                function CreateBridgeTalkMessage() {

                          var bt = new BridgeTalk();

                          bt.target = "photoshop";

                          bt.body = myResizeImage.toSource() + "('" + imagePath + "'," + hScale + "," + vScale + ");";

                          bt.send();

                }

      }

       

      function myResizeImage(imagePath, hScale, vScale) {

                var myFile = new File(imagePath);

                var myDoc = app.open(myFile);

          var  oh=myDoc.width.value * hScale *0.010;

          var ov=myDoc.height.value * vScale*0.010;

          var oh=oh+12.00;

          var ov=((ov*(oh+12.00))/oh);

                myDoc.resizeImage(oh,ov, 350);

      }

        • 1. Re: what is wrong?  with ID script ,auto change image size use photoshop?
          XH.XH Level 1

          function myResizeImage(imagePath, hScale, vScale) {

              app.preferences.rulerUnits = Units.MM;    //try to add this code

              var myFile = new File(imagePath);

              var myDoc = app.open(myFile);

              var  oh=myDoc.width.value * hScale *0.010;

              var ov=myDoc.height.value * vScale*0.010;

              var oh=oh+12.00;

              var ov=((ov*(oh+12.00))/oh);

                    myDoc.resizeImage(oh,ov, 350);

          }

          • 2. Re: what is wrong?  with ID script ,auto change image size use photoshop?
            喜狼_edny Level 1

            thank you very much

            I will try, and reback

            • 3. Re: what is wrong?  with ID script ,auto change image size use photoshop?
              喜狼_edny Level 1

              I have chang  my script,but it is still wrong.

              and please do not put the Note in "function myResizeImage(imagePath, hScale, vScale) {"

              Otherwise,the scrip can't be run.

              I Provide examples file,you can down here

              http://pan.baidu.com/share/link?shareid=985517990&uk=3389450479

               

              below  is my change:

              ------------------------------------------------------------------------------------------ -------------------------------------------

              Main();

              function Main() {

                        var image = app.selection[0].images[0];

                        var imagePath = image.itemLink.filePath;

                        var hScale = image.horizontalScale;

                        var vScale = image.verticalScale;

                        CreateBridgeTalkMessage();

               

                        function CreateBridgeTalkMessage() {

                                  var bt = new BridgeTalk();

                                  bt.target = "photoshop";

                                  bt.body = myResizeImage.toSource() + "('" + imagePath + "'," + hScale + "," + vScale + ");";

                                  bt.send();

                        }

              }

              //

              function myResizeImage(imagePath, hScale, vScale) {

                   app.bringToFront();

                  app.preferences.rulerUnits = Units.MM;

                        var myFile = new File(imagePath);

                        var myDoc = app.open(myFile);

                  var  w=myDoc.width.value * hScale*0.01;

                  var h=myDoc.height.value * vScale*0.01;

                  var k=w+12.00;

                  var j=h*k/w;

                        myDoc.resizeImage(k,j, 350);

                 

                  }

              • 4. Re: what is wrong?  with ID script ,auto change image size use photoshop?
                喜狼_edny Level 1

                I make alert() check where, then I find alert(myDoc.width.value) is different so much,but the tow picture's width is Almost。

                • 5. Re: what is wrong?  with ID script ,auto change image size use photoshop?
                  XH.XH Level 1

                  Hi, 喜狼_edny.

                   

                  Try the following code:

                  Main();

                  function Main() {

                      var image = app.selection[0].images[0];

                      var imagePath = image.itemLink.filePath;

                      var myResolution=350;

                      var hScale=image.horizontalScale*(myResolution/image.actualPpi[0]);

                            var vScale=image.verticalScale*(myResolution/image.actualPpi[1]);

                      CreateBridgeTalkMessage();

                   

                      function CreateBridgeTalkMessage() {

                          var bt = new BridgeTalk();

                          bt.target = "photoshop";

                          bt.body = myResizeImage.toString() + "\rmyResizeImage('" + imagePath + "'," + hScale + "," + vScale +","+myResolution+ ");";     

                          bt.send();

                      }

                  }

                  function myResizeImage(imagePath, hScale, vScale,myResolution) {

                      app.bringToFront();

                      app.preferences.rulerUnits = Units.MM;

                      var myFile = new File(imagePath);

                      var myDoc = app.open(myFile);

                      myDoc.resizeImage(undefined,undefined, myResolution,ResampleMethod.NONE);

                      var  w=myDoc.width.value * hScale*0.01;

                      var h=myDoc.height.value * vScale*0.01;

                      var k=w+12.00;

                      var j=h*k/w;

                      myDoc.resizeImage(k,j, myResolution,ResampleMethod.BICUBICSMOOTHER);

                  }

                  • 6. Re: what is wrong?  with ID script ,auto change image size use photoshop?
                    XH.XH Level 1

                    change the resolution and size should be divided into two steps.

                    • 7. Re: what is wrong?  with ID script ,auto change image size use photoshop?
                      喜狼_edny Level 1

                      HA,HA,you are right~

                      Thank you very very very much,

                      excellent ,you

                      • 8. Re: what is wrong?  with ID script ,auto change image size use photoshop?
                        喜狼_edny Level 1

                        a little problem need help

                        if you Careless to Consecutive double-click the picture

                        you will find the imagesize is Smaller

                        could you Determine the image  whether to open,if not run the scrip,

                        if open, run the script from Somewhere

                        • 9. Re: what is wrong?  with ID script ,auto change image size use photoshop?
                          XH.XH Level 1

                          喜狼_edny wrote:

                           

                          a little problem need help

                          if you Careless to Consecutive double-click the picture

                          you will find the imagesize is Smaller

                          could you Determine the image  whether to open,if not run the scrip,

                          if open, run the script from Somewhere

                           

                          Don't understand your question.

                          • 10. Re: what is wrong?  with ID script ,auto change image size use photoshop?
                            喜狼_edny Level 1

                            I mean I have run Once the scrip,and the image is open. I Careless to run the scrip again, I find the image is change to smaller,

                            when the image is opened if you run the scrip again, you will find the image is smaller

                            • 11. Re: what is wrong?  with ID script ,auto change image size use photoshop?
                              XH.XH Level 1

                              Execute the script to save images, close and update it, execute the script again, pictures not smaller.

                               

                              Please look at:

                              Main();
                              function Main() {
                                  var image = app.selection[0].images[0];
                                  var imagePath = image.itemLink.filePath;
                                  var myResolution=350;
                                  var hScale=image.horizontalScale*(myResolution/image.actualPpi[0]);
                                  var vScale=image.verticalScale*(myResolution/image.actualPpi[1]);
                                  var result=CreateBridgeTalkMessage();
                                  if(result&&image.itemLink.status==LinkStatus.LINK_OUT_OF_DATE)image.itemLink.update();
                              
                              
                                  function CreateBridgeTalkMessage() {
                                      var bt = new BridgeTalk();
                                      var re;
                                      bt.target = "photoshop";
                                      bt.body = myResizeImage.toString() + "\rmyResizeImage('" + imagePath + "'," + hScale + "," + vScale +","+myResolution+ ");";      
                                      bt.onResult = function(e) {
                                        re= e.body;
                                      } 
                                      bt.send(900);
                                      return re;
                                  }
                              }
                              function myResizeImage(imagePath, hScale, vScale,myResolution) {
                                  app.bringToFront();
                                  app.displayDialogs = DialogModes.NO;
                                  app.preferences.rulerUnits = Units.MM;
                                  var myFile = new File(imagePath);
                                  var myDoc = app.open(myFile);
                                  myDoc.resizeImage(undefined,undefined, myResolution,ResampleMethod.NONE);
                                  var  w=myDoc.width.value * hScale*0.01;
                                  var h=myDoc.height.value * vScale*0.01;
                                  var k=w+12.00;
                                  var j=h*k/w;
                                  myDoc.resizeImage(k,j, myResolution,ResampleMethod.BICUBICSMOOTHER);
                                  myDoc.save();
                                  myDoc.close();
                                  return true;
                              }
                              
                              
                              • 12. Re: what is wrong?  with ID script ,auto change image size use photoshop?
                                喜狼_edny Level 1

                                auto save?

                                if it is jpg

                                Are you sure saved with High quality?

                                if The last time the image is saved with Low quality by somebody, It will auto save with low quality. It is very Dangerous.

                                mybe,just forbid me to run the script again,when the image is opened~~~

                                 

                                thank you~

                                best wishes for you

                                • 13. Re: what is wrong?  with ID script ,auto change image size use photoshop?
                                  XH.XH Level 1

                                  image opened, the script is not executed:

                                   

                                  Main();
                                  function Main() {
                                      try{var image = app.selection[0].images[0];}catch(e){return}
                                      var imagePath = image.itemLink.filePath;
                                      var myResolution=350;
                                      var hScale=image.horizontalScale*(myResolution/image.actualPpi[0]);
                                      var vScale=image.verticalScale*(myResolution/image.actualPpi[1]);
                                      CreateBridgeTalkMessage();
                                      function CreateBridgeTalkMessage() {
                                          var bt = new BridgeTalk();
                                          bt.target = "photoshop";
                                          bt.body = myResizeImage.toString() + "\rmyResizeImage('" + imagePath + "'," + hScale + "," + vScale +","+myResolution+ ");"; 
                                          bt.send();
                                      }
                                  }
                                  function myResizeImage(imagePath, hScale, vScale,myResolution) {
                                      for(var i=0;i<app.documents.length;i++)  if(app.documents[i].fullName.fsName==imagePath)return;  //if image opend 
                                      app.bringToFront();
                                      app.preferences.rulerUnits = Units.MM;
                                      var myFile = new File(imagePath);
                                      var myDoc = app.open(myFile);
                                      myDoc.resizeImage(undefined,undefined, myResolution,ResampleMethod.NONE);
                                      var  w=myDoc.width.value * hScale*0.01;
                                      var h=myDoc.height.value * vScale*0.01;
                                      var k=w+12.00;
                                      var j=h*k/w;
                                      myDoc.resizeImage(k,j, myResolution,ResampleMethod.BICUBICSMOOTHER);
                                  }
                                  
                                  
                                  • 14. Re: what is wrong?  with ID script ,auto change image size use photoshop?
                                    喜狼_edny Level 1

                                    It is very good

                                    thank you very much

                                    You're amazing

                                    Best wishes  to you

                                    mybe you can help another question:change fonts like indesign in ps,Specifically for the missing fonts

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

                                    • 15. Re: what is wrong?  with ID script ,auto change image size use photoshop?
                                      喜狼_edny Level 1

                                      Hi XH.XH I miss you.

                                      For a long time did not come, found the forum changed, I almost lost you!

                                      There is a trap in this script, Need your help.

                                      ------------------------------------------------------------------------------------------ -----------------------------

                                      When the picture is Squashed.

                                      Have diffrent horizontal and vertical scaling.

                                      Run the script,the picture will be smaller,It is change from 80%,not 100%

                                      ------------------------------------------------------------------------------------------ -----------------------------

                                      and it can't run,when you use the white White arrow(Direct Selection Tool)



                                      nomal.jpg

                                      diffrent.jpg