15 Replies Latest reply on Sep 1, 2015 11:37 AM by changed screen name 1231

    Photoshop Actions

    Amanda10990 Level 1

      I have multiple images with different colored backgrounds, and I need to place a logo onto each image. Some of my images have lighter backgrounds, while some are darker and I will need to place a light logo on the darker images, and a dark logo on the light images so they will clearly show up. Is there a way for me to create a Photoshop action that will allow the program to detect the value of the images and place the light or dark logo on the image accordingly? I am currently working with Creative Cloud.

       

      I would really appreciate any help that I can get on the matter. Thanks for reading!

        • 1. Re: Photoshop Actions
          c.pfaffenbichler Level 9

          If the two logos are indeed different files I see no option to accomplish this with an Action and it would probably need Scripting.

          Though you may have give some thought to how exactly the different conditions can be unambiguously identified.

          Photoshop Scripting

          1 person found this helpful
          • 2. Re: Photoshop Actions
            Amanda10990 Level 1

            I was wondering if there might be a way for me to use the eyedropper tool to determine the value of the background and which logo would need to be placed into the image. I wasn't quite sure if this is even possible, but I thought I would check.

            • 4. Re: Photoshop Actions
              c.pfaffenbichler Level 9

              Use the eyedropper where exactly?

              With which Sample Size?

               

              The Eyedropper Tool can be used in a Script but you need to be clear about what you want to achieve and how you arrive at the distinctions the conditional operations shall be based on.

              1 person found this helpful
              • 5. Re: Photoshop Actions
                Amanda10990 Level 1

                I was planning on using the eyedropper tool at the bottom right corner of the images with maybe a sample size of 5x5 average.

                • 6. Re: Photoshop Actions
                  c.pfaffenbichler Level 9

                  Another option would be using the Filter "Average" and the histogram to determine the brightness of the complete image.

                  But if the bottom right corner is a reliable indicator that’s fine.

                   

                  What exactly would be the steps in the Action (save the conditional clause that determines which logo to use)?

                  1 person found this helpful
                  • 7. Re: Photoshop Actions
                    Amanda10990 Level 1

                    I really appreciate your help. I suppose I am not exactly sure how this would work. I am mainly skilled in using Illustrator rather than Photoshop, but I have used actions in the past for adding effects to photos. Basically, I am creating some illustrations (possibly hundreds) and I need to have my company's logo at the bottom right corner of each illustration. Some of these illustrations will be too light for a light logo and others will be too dark for a dark logo. If it is possible, I need to create an action or script that can detect the lightness or darkness of my illustrations and either place a light or dark logo in the bottom right corner as necessary. That is really all that I need the action or script to do for me aside from possibly saving the files to another folder. 

                    • 8. Re: Photoshop Actions
                      c.pfaffenbichler Level 9

                      If no one else provides a sample script in the meantime I expect I will be able to look into it later on, maybe on the weekend.

                      1 person found this helpful
                      • 9. Re: Photoshop Actions
                        c.pfaffenbichler Level 9

                        Setting the Sample Size would be bothersome so I decided on the Average approach.

                        Edit: The Script creates a flattened duplicate of the image, crops it to the bottom right 5px x 5px, averages that, determines the Lab luminance value and closes the duplicate without saving.

                        Depending on the image’s size this may take a while, but hopefully it is fast enough for your purposes.

                         

                        If you want to give it a try, paste the following text into a new file in ExtendScript Toolkit or a text editor and save it as a jsx-file into Photoshop’s Presets/Scripts-folder.

                        After restarting Photoshop the Script should be available under File > Scripts and can be assigned a Keyboard Shortcut directly, recorded into an Action or started from ExtendScript Toolkit directly.

                        // 2015, use it at your own risk;
                        #target "photoshop-90.032"
                        if (app.documents.length > 0) {
                        // set to pixels;
                        var originalRulerUnits = app.preferences.rulerUnits;
                        app.preferences.rulerUnits = Units.PIXELS;
                        var theSize = 5;
                        var myDocument = app.activeDocument;
                        // check image is at least as big as sample size;
                        if (myDocument.width >= theSize && myDocument.height >= theSize) {
                        ////////////////////////////////////
                        // create a duplicate to measure;
                        var theDuplicate = myDocument.duplicate("theDuplicate", true);
                        theDuplicate.resizeCanvas(theSize, theSize, AnchorPosition.BOTTOMRIGHT);
                        // apply filter average;
                        theDuplicate.layers[0].applyAverage();
                        // create a sampler;
                        var theSampler = theDuplicate.colorSamplers.add([theSize/2, theSize/2]);
                        var theB = theSampler.color.lab.l;
                        // close the duplicate;
                        theDuplicate.close(SaveOptions.DONOTSAVECHANGES);
                        ////////////////////////////////////
                        // the result;
                        if (theB > 50) {alert ("lower right corner is light")}
                        else {alert ("lower right corner is dark")};
                        };
                        // reset;
                        app.preferences.rulerUnits = originalRulerUnits;
                        };
                        
                        

                         

                        The alerts are stand-ins to illustrate the cases.

                        You could either amend the Script itself to place the logos or run two different Actions depending on the result with

                        app.doAction("Action 1", "Set 1");
                        
                        

                        where the first argument is the Action’s name and the second the Action Set’s name.

                        1 person found this helpful
                        • 10. Re: Photoshop Actions
                          Amanda10990 Level 1

                          I can't thank you enough for your help! I really appreciate it.

                          I will have to let you know how it goes once I give this a try.

                          Thanks again!

                          • 11. Re: Photoshop Actions
                            michelr31372089 Level 2

                            As c.pfaffenbichler wrote it, I should use the Average Filter (excuse my bad English).

                             

                            You know where you have to copy your logo. This place depends on width and height of the photo and of the logo. You can create a temp layer of the area where the logo must be copied. On this layer, you apply the average filter and get its RGB values. If R+G+B>382 the background is light, else it is dark. Now you can destroy the temp layer and apply the good logo on your photo.

                            • 12. Re: Photoshop Actions
                              Philip Cord Level 4

                              That is not going to work. What if it is all Black? RGB will all be 0

                              • 13. Re: Photoshop Actions
                                Benjamin Root MVP & Adobe Community Professional

                                How about throwing in an else if? I've just started learning Java Script, so I'm pretty much a novice

                                • 14. Re: Photoshop Actions
                                  michelr31372089 Level 2

                                  In the folowing exemple you will know if the surface of the photo where you intend to copy a clear or a dark logo is rather dark or not.

                                   

                                  // MAC Finder ou WINDOWS Explorer

                                  #target photoshop

                                  app.bringToFront();

                                   

                                  var userUnit = app.preferences.rulerUnits;

                                  var userType = app.preferences.typeUnits;

                                  app.preferences.rulerUnits = Units.PIXELS;

                                  app.preferences.typeUnits = TypeUnits.PIXELS;

                                       

                                  var logoHeight = 55; // Example

                                  var logoWidth = 55;

                                  var docRef = app.activeDocument;

                                  var docWidth = docRef.width;

                                  var docHeight = docRef.height;

                                   

                                   

                                  var x1 = docWidth - logoWidth - 10;

                                  var x2 = docWidth - 10;

                                  var y1 = docHeight - logoHeight - 10;

                                  var y2 = docHeight - 10;

                                   

                                  var A= Array(x1, y1);

                                  var B = Array(x2,y1);

                                  var C = Array(x2, y2);

                                  var D = Array(x1, y2);

                                  var myRegion = Array(A, B, C, D);

                                   

                                  docRef.selection.select(myRegion);

                                  docRef.selection.copy();

                                   

                                   

                                  // You create a temp document

                                  documents.add();

                                  app.activeDocument.resizeCanvas(UnitValue(logoWidth,"px"),UnitValue(logoHeight,"px"));

                                  app.activeDocument.paste();

                                  var layerRef = app.activeDocument.artLayers[0];

                                  layerRef.applyAverage();

                                   

                                  var sampler = app.activeDocument.colorSamplers.add([1, 1]);

                                  var average = sampler.color.rgb.red + sampler.color.rgb.green + sampler.color.rgb.blue;

                                  var luminosity = true;

                                  if (average<383) luminosity = false;

                                  app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

                                  alert(luminosity);

                                   

                                   

                                  /* NOW YOU KNOW IF THE AVERAGE OF THE BACKGROUND COLOR IS DARK OR LIGHT

                                  IF  LIGHTNESS IS TRUE YOU LOAD AND COPY THE DARK LOGO

                                  ELSE YOU LOAD AND COPY THE LIGHT ONE

                                  */

                                   

                                   

                                  // Restores the user's preferences

                                  app.preferences.rulerUnits = userUnit;

                                  app.preferences.typeUnits = userType;

                                  1 person found this helpful
                                  • 15. Re: Photoshop Actions
                                    Level 1

                                    I think you must place a dark logo on the light image and a light logo on a light image. if that makes sents