3 Replies Latest reply on Apr 16, 2011 2:31 AM by Anstellos1

    Detecting Megapixels to do proper actions

    Anstellos1

      Hi,

       

      I am a photographer. here is the situation:

       

      I have several pictures from different cameras (different megapixels) and different files format (RAW JPG)

      I'm looking for a javascript that tells photoshop to "detect" the document megapixels and then apply an action I already created.

       

      it would go like:

       

      If active document megapixel count is < 5 MP then do action 5 MP -

      If active document megapixel count is between 5 MP and 10 MP then do action 5-10 MP

      If active document megapixel count is between 10 MP and 15 MP then do action 10-15 MP ect...

       

      the problem is I don't find a command that would make a "pixel count" if I use the document size I m worried that a big raw file would be detect as "big megapixels" and a small jpegs like it was a small megapixels if it makes sense ?

       

      Do you have an idea ? How would you write that in java script ?

       

       

      regards

        • 1. Re: Detecting Megapixels to do proper actions
          Paul Riggott Level 6

          You could do something like this...

           

          #target photoshop
          main();
          function main(){
          if(!documents.length) return;
          var Width = activeDocument.width.as('px');
          var Height = activeDocument.height.as('px');
          var megaPixels = (((Width * Height) / 1000)/1000).toFixed(3);
          //amend ActionName,ActionSet to suit.
          if(megaPixels < 5) doAction("ActionName","ActionSet");
          if(megaPixels >= 5 && megaPixels < 10) doAction("ActionName","ActionSet");
          if(megaPixels >= 10 ) doAction("ActionName","ActionSet");
          }
          
          1 person found this helpful
          • 2. Re: Detecting Megapixels to do proper actions
            Anstellos1 Level 1

            Thanks its working like a charm ^^

            • 3. Re: Detecting Megapixels to do proper actions
              Anstellos1 Level 1

              I would like now to go a bit further:

              First I would like to detect document megapixel size using your script (working!)

              then if the megapixel count is bigger than 1.35 MP (1350px) I will have a new script detecting if the document is horizontal, vertical or a square. in fact my actions resize document to be maximum 1350 px wide or height. Maybe I can write the command directly into the script instead of calling actions ? is there a way to transform a photoshop action directly into java script ?

               

              the correct formula doesn't look like "else"

              I wrote it this way but its not working, an idea?

               

              #target photoshop

              main();

              function main(){

              if(!documents.length) return;

              var doc = activeDocument;

              var Width = activeDocument.width.as('px');

              var Height = activeDocument.height.as('px');

              var megaPixels = (((Width * Height)).toFixed(3);

              if(megaPixels < 1350) doAction("action","action set");

              }

              else

              var doc = activeDocument;

              if(doc.width.value>=doc.height.value){//Landscape

              doAction("actionH", "action set");

              }else if(doc.width.value==doc.height.value){//square

              doAction("actionH", "action set");

              }else{//Portrait

              doAction("actionV", "action set");

              }