24 Replies Latest reply: Feb 21, 2012 11:17 PM by c.pfaffenbichler RSS

    Photoshop Automation color replacement

    ginostylz

      How would you go about taking a somewhat transparent overlay and replacing the colors of the underlying layers and exporting to many files? I saw how Photoshop has a "Pixel Replacement" feature but you need to supply it with jpgs to swap instead of color codes. I'd prefer just color codes so I wouldn't have to make a ton of images.

       

      If you could point me in the right direction I would appreciate it.

        • 1. Re: Photoshop Automation color replacement
          c.pfaffenbichler Community Member

          Could you please post screenshots/mock-ups to illustrate what you are trying to achieve.

          • 2. Re: Photoshop Automation color replacement
            ginostylz Community Member

            bevelandembosschips2.png

            I have about 50,000 to make in different paint sample colors. Some are metallic or pearl paint swatches, while others are solid.  I may need some bevel and emboss, or some type of highlight too, but this is the best I had on my home computer.

            • 3. Re: Photoshop Automation color replacement
              c.pfaffenbichler Community Member

              I think you are not giving enough detail for us to provide sensible advice.

               

              What is the source, what is the result supposed to be (including Layer structure, transparencies, file formats), what is the data on which the changes are supposed to be based, …?

              • 4. Re: Photoshop Automation color replacement
                ginostylz Community Member

                I have a database collected of over 50,000 different paint colors taken from a multi angle spectrophotometer with 25,45, and 75 degrees. The colors are natively Lab, but I also have them converted to RGB also.  I can re-export them in almost anyway that photoshop would need them, prefferably not a solid colored jpg with a filename so that photoshop could use it.    From that I'd like to blend two angles maybe a 25 and a 45 to get a more accurate color to display. Metallic colors may get an add noise filter to simulate the metallic.  I haven't found a perfect formula in photoshop just yet that gets acceptable results everytime. I am still working out the small details.

                 

                bevelandembosschipsforadobe.jpg

                • 5. Re: Photoshop Automation color replacement
                  c.pfaffenbichler Community Member

                  Either it is just me having a hard time understanding what you are trying to achieve and what the source and intended final material is or you don’t communicate your intentions well, but I’ll give it another try:

                  If you have a database of Lab values you could use that to populate a layered file with Solid Color Layers for example (or edit existing Solid Color Layers).

                  • 6. Re: Photoshop Automation color replacement
                    ginostylz Community Member

                    Source: is an automotive paint scan taken from 3 angles.

                    The spectophotometer scans 3 angles face, flash, and side tones. I get cie or hunter Lab color from the device, but I convert the color to RGB on my end. So I can use either LAB or RGB colors taken from 3 angles to try to recreate a paint chip swatch.

                    The light source that the specrophotometer uses is D65, or daylight.

                     

                    The final material is a paint chip swatch to be veiwed over a web browser/computer monitor.

                     

                    I think I can get there by applying a 25 degree angle on one layer, and a 45 degree angle on another angle and use soft light as my blending options.

                    • 7. Re: Photoshop Automation color replacement
                      c.pfaffenbichler Community Member

                      In what form is the data available? A CSV-file …?

                      And what RGB-space did you convert to?

                       

                      If you want to use the angled measurements for the bevels I suppose you could create a sample file consisting of three Solid Color Layers with appropriate Layer Masks and then use the data to change those and save copies off of that file.

                      • 8. Re: Photoshop Automation color replacement
                        ginostylz Community Member

                        The database starts as microsoft SQL, however I can export it to a csv or other file type for the purpose of integrating to adobe for the job. I used easyRGB for the conversion math, they didn't specify what type of RGB. I am open to using a different set of match for the conversion, but there isn't a lot of resouces online. 

                        • 9. Re: Photoshop Automation color replacement
                          c.pfaffenbichler Community Member

                          Don’t think I ever heard if »easyRGB«, you might be better off sticking with Lab.

                          • 10. Re: Photoshop Automation color replacement
                            ginostylz Community Member

                            Adobe makes you round to the nearest integer, A and B values really need the decimal. Easyrgb.com has color conversions to go from LAB to XYZ to RGB, and several other color spaces. It isn't perfect, but it's the best I have unless you can name some better sources.

                             

                            The biggest challenge is to automate the whole process. Adobe photoshop appears to only swap text efficiently, and also replace pixels if I supplied the jpgs. I don't see a way to replace colors with the scripting options.

                            • 11. Re: Photoshop Automation color replacement
                              c.pfaffenbichler Community Member

                              Have I mentioned SOLID COLOR LAYERS yet?

                              Not to mention that you could set the Foreground Color via Script and fill …

                              I recommend that you create a sample file with SOLID COLOR LAYERS and if structure is necessary do that with a Layer set to the appropriate Blend Mode.

                               

                              Unless you know in which RGB-space those results are they would seem to be pretty much worthless.

                              • 12. Re: Photoshop Automation color replacement
                                ginostylz Community Member

                                The only 3 variable I saw are below. I didn't find how to set a layer or foreground to auto fill with an RGB color which is why I am here. Trying to mass produce 50,000 image files is new to me. I couldn't find anything in the adobe photoshop help articles. I know how to manually set a solid colored layer and save it manually, but I am trying to avoid manually setting color and naming each file.

                                 

                                http://help.adobe.com/en_US/Photoshop/11.0/WSfd1234e1c4b69f30ea53e41001031ab64-7414a.html

                                Visibility
                                Shows or hides the content of the layer.

                                Pixel Replacement

                                Replaces the pixels in the layer with pixels from another image file.

                                Text Replacement

                                Replaces a string of text in a type layer.

                                 

                                For Pixel Replacement variables, set the following options. 

                                •   Choose a method for scaling the replacement image: Fit scales the image so that it fits in the bounding box (which may leave parts of the bounding box empty), Fill scales the image so that it fills the bounding box entirely (which may cause the image to extend beyond the bounding box), As Is applies no scaling to the image, and Conform scales the image non-proportionally so that it fits in the bounding box.
                                • 13. Re: Photoshop Automation color replacement
                                  c.pfaffenbichler Community Member

                                  It is possible to change the color of a Solid Color Layer via Script and saving (a copy of) that can also be done via Script.

                                  If the angled measurements are intended to be incorporated I think that might also be done with Solid Color Layers with Layer Masks.

                                  aTest.jpg

                                  • 14. Re: Photoshop Automation color replacement
                                    ginostylz Community Member

                                    The scripting part is what is stumping me. Do you have a reading resource for that so I can review it with my programmer and web designer?

                                    • 15. Re: Photoshop Automation color replacement
                                      WebNola

                                      I am working with Ginostylz on this project. Let me try to put this as best I can:

                                       

                                      There are three layers in the photoshop file.

                                       

                                      1) Layer 1 sits on top of the other two, and it has a somewhat transparent overlay with some light effects on it on it. This layer gives the colors in the underlying layers the desired effect.

                                       

                                      2) Layer 2 is one of two colors we'd like to pull from a CSV file. It can be just a flat color that fills up the whole layer. It has a "hard light" layer mode on it.

                                       

                                      3) Layer 3 is the second of two colors we'd like to pull from a CSV file.  It can be just a flat color that fills up the whole layer.

                                       

                                      In our research with Adobe's help site entitled "creating data driven graphics", it looks like we have two choices, both of which seem way harder than it could/should be.

                                       

                                      1) Option 1: Use the "Pixel Replacement" feature to pull the colors in. To do this, we'd have to create 100,000 images with flat colors and then pull them in

                                       

                                      2) Option 2: Use the "Visibility" feature to selectively show/hide layers of different colors. To do this, we'd have to create 100,000 layers with flat colors.

                                       

                                      What we'd like to be able to do at this point is to simply replace the RGB of layers 2 and 3 using a CSV file and then export to create many images. Is this possible? If not, how would you go about this?

                                      • 16. Re: Photoshop Automation color replacement
                                        c.pfaffenbichler Community Member

                                        Is this possible? If not, how would you go about this?

                                        Quite frankly I practically never use the »data driven graphics«-feature.

                                        In this case a custom Script may be the best way to go, too.

                                         

                                        A couple of the more experienced contributors here and over at ps.scripts.com (you could also search for csv-file-related threads there) offer their services professionally – and I think there would be advantages to taking them up on that in this case especially if speed is a concern.

                                        But they are usually also very generous with their advice and help so you may yet get all the advice you need here for free.

                                        • 17. Re: Photoshop Automation color replacement
                                          c.pfaffenbichler Community Member

                                          Edited:

                                          For example:

                                          I have a txt-file with this text:

                                          color1;20;30;40;
                                          color2;60;70;80;
                                          color3;60;50;40;
                                          

                                          and a file »testEmboss-psd« open and active in Photoshop with a top-level (meaning it is not in a Group) Solid Color Layer with the name »colorLayer«; the Script at the bottom will get me these:

                                          resultingFiles.jpg

                                          // 2012, use it at your own risk;
                                          // thanks to xbytor;
                                          #target photoshop
                                          if (app.documents.length > 0) {
                                          var myDocument = app.activeDocument;
                                          var documentName = myDocument.name;
                                          var basename = documentName.match(/(.*)\.[^\.]+$/)[1];
                                          // get path;
                                          try {var documentPath = myDocument.path}
                                          catch (e) {var documentPath = "~/Desktop"};
                                          // psd options;
                                          psdOpts = new PhotoshopSaveOptions();
                                          psdOpts.embedColorProfile = true;
                                          psdOpts.alphaChannels = false;
                                          psdOpts.layers = true;
                                          psdOpts.spotColors = true;
                                          // get file;
                                          if ($.os.search(/windows/i) != -1) {var theFile = File.openDialog ("please select files", "*.txt", false)} 
                                          else {var theFile = File.openDialog ("please select files", getFiles, false)};
                                          if (theFile) {
                                          var theText = readPref(theFile);
                                          var theArray = theText.split("\n");
                                          //
                                          try {
                                          var theLayer = myDocument.layers.getByName("colorLayer");
                                          // work through list;
                                          for (var m = 0; m < theArray.length; m++) {
                                          var thisText = theArray[m].split(";");
                                          alert (thisText.join("\n\n"));
                                          var theName = thisText[0];
                                          editSolidFill (thisText[1], thisText[2], thisText[3], theLayer);
                                          // save psd;
                                          myDocument.saveAs((new File(documentPath+"/"+basename+"_"+theName+".psd")),psdOpts,true);
                                          }
                                          }
                                          catch (e) {};
                                          };
                                          };
                                          ////// function to change solid fill layers //////
                                          function editSolidFill (theL, theA, theB, theLayer) {
                                          app.activeDocument.activeLayer = theLayer;
                                                    // =======================================================
                                          var idsetd = charIDToTypeID( "setd" );
                                              var desc3 = new ActionDescriptor();
                                              var idnull = charIDToTypeID( "null" );
                                                  var ref2 = new ActionReference();
                                                  var idcontentLayer = stringIDToTypeID( "contentLayer" );
                                                  var idOrdn = charIDToTypeID( "Ordn" );
                                                  var idTrgt = charIDToTypeID( "Trgt" );
                                                  ref2.putEnumerated( idcontentLayer, idOrdn, idTrgt );
                                              desc3.putReference( idnull, ref2 );
                                              var idT = charIDToTypeID( "T   " );
                                                  var desc4 = new ActionDescriptor();
                                                  var idClr = charIDToTypeID( "Clr " );
                                                      var desc5 = new ActionDescriptor();
                                                      var idLmnc = charIDToTypeID( "Lmnc" );
                                                      desc5.putDouble( idLmnc, theL );
                                                      var idA = charIDToTypeID( "A   " );
                                                      desc5.putDouble( idA, theA );
                                                      var idB = charIDToTypeID( "B   " );
                                                      desc5.putDouble( idB, theB );
                                                  var idLbCl = charIDToTypeID( "LbCl" );
                                                  desc4.putObject( idClr, idLbCl, desc5 );
                                              var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );
                                              desc3.putObject( idT, idsolidColorLayer, desc4 );
                                          executeAction( idsetd, desc3, DialogModes.NO );
                                          };
                                          ////// read prefs file //////
                                          function readPref (thePath) {
                                            if (File(thePath).exists == true) {
                                              var file = File(thePath);
                                              file.open("r");
                                              file.encoding= 'BINARY';
                                              var theText = new String;
                                              for (var m = 0; m < file.length; m ++) {
                                                theText = theText.concat(file.readch());
                                                };
                                              file.close();
                                              return String(theText)
                                              }
                                            };
                                          ////// get psds, tifs and jpgs from files //////
                                          function getFiles (theFile) {
                                              if (theFile.name.match(/\.(txt)$/i)) {
                                                  return true
                                                  };
                                                    };
                                          
                                          • 18. Re: Photoshop Automation color replacement
                                            WebNola Community Member

                                            Thank you. I think this script will work, if I could get it to work on my end - having a little problem with that, though.

                                             

                                            I took the code you provided and made a .jsx file out of it. I renamed my psd testEmboss-psd (also tried testEmboss.psd - not sure if it mattered). I made a new layer with the name colorLayer and gave it a flat color with the paint bucket tool. I also created a list.txt file with the values, identical to how you have it.

                                             

                                            I tried to run the script by going to file>scripts>browse and selecting the .jsx file. It then instantly asks me for a text file, and i open list.txt. The only thing that happens at this point is a white alert box which seems to give me the first line of the txt file (double spaced). Any ideas?Capture.JPG

                                            • 19. Re: Photoshop Automation color replacement
                                              Muppet Mark Community Member

                                              Did you OK it… If you don't want the alert then remove the line…

                                               

                                              alert (thisText.join("\n\n"));

                                               

                                              or comment it out with

                                               

                                              //alert (thisText.join("\n\n"));

                                              • 20. Re: Photoshop Automation color replacement
                                                WebNola Community Member

                                                When I hit "Ok", nothing seems to happen.

                                                 

                                                I tried commenting out the alert, and now nothing happens at all, no alert, nothing. Nothing seemed to happen except the alert before, but now nothing at all seems to happen at all.

                                                • 21. Re: Photoshop Automation color replacement
                                                  c.pfaffenbichler Community Member

                                                  How often do I need to point out »Solid Color Layers«?

                                                  According to your screenshot you seem to have named a normal Layer »colorLayer« and not, as instructed, a Solid Color Layer.

                                                  • 23. Re: Photoshop Automation color replacement
                                                    WebNola Community Member

                                                    Using "Solid Color" from the "Create new fill or adjustment layer" menu, I got it to work successfully as it did for you.

                                                     

                                                    Now I need to know how to add a second color layer that I can control from a second set of variables in each image. I also need to know how to save as a jpg instead of a psd.

                                                     

                                                    Thank you very much for your help so far!

                                                    • 24. Re: Photoshop Automation color replacement
                                                      c.pfaffenbichler Community Member

                                                      Just add the additional info in the text (like this maybe

                                                      color1;20;30;40;color2;50;60;70;

                                                      ) and get a second Layer by its name (in the case of »colorLayer2« something like

                                                      var theOtherLayer = myDocument.layers.getByName("colorLayer2");

                                                      ), then add the correct line to edit it.

                                                      editSolidFill (thisText[5], thisText[6], thisText[7], theOtherLayer); 


                                                      For figuring out how to save jpgs check out ExtendScript Toolkot’s Help > Object Model Viewer or search for a Script that does a JPG-save or refer to »Photoshop CS5 JavaScript Ref.pdf« and »Photoshop CS5 Scripting Guide.pdf«.

                                                      jpgSaveOptionsObjectModelViewer.jpg