10 Replies Latest reply on Mar 5, 2018 9:41 AM by pixxxel schubser

    Color Comparison Script

    Ethan J.

      Hi, I'm very new to Photoshop (I haven't really dabbled in scripts all that much), but one thing I wanted to try to do was to see if there were a way to compare colors using hexadecimal codes entered on a text layer, and for the background and text colors to automatically update accordingly, with the background being the exact hex code in question, and the text color being a slightly darker version of that color for contrast and readability's sake. At the moment, I'm doing all of this manually.

      Color Comparisons.jpg

      Above is a picture of what the document basically looks like now. Please note that I'm using the text overlay layer effect to color the text rather than just coloring the text itself.

       

      I don't know the complexity or viability of such a script, but I would appreciate any help you could give me!

        • 1. Re: Color Comparison Script
          pixxxel schubser MVP & Adobe Community Professional

          Hi Ethan J.,

          please give an example document before and after and describe your workflow in detail.

           

          The question of complexity of a script depends on the exact details.

          Do you want to write the script by yourself?

          • 2. Re: Color Comparison Script
            Ethan J. Level 1

            Thanks for the reply!

             

            Here's a link to the .psd file. As for describing my workflow, I'm not quite sure what you mean by that. Could you elaborate?

             

            Also, it's not quite necessary for me to do it by myself, all I would like is a functioning script, if at all possible.

            • 3. Re: Color Comparison Script
              pixxxel schubser MVP & Adobe Community Professional

              Is this the only document? How it looks like before you work with it? And how - after?

              https://forums.adobe.com/people/Ethan+J.  schrieb

               

              Thanks for the reply!

              … a link to the .psd file. As for describing my workflow, I'm not quite sure what you mean by that. Could you elaborate?

               

              You open the document.

              And what is your second step?

              … third step?

              … last step?

              • 4. Re: Color Comparison Script
                Ethan J. Level 1

                Well, the document I provided is how it looks after I mess with it. The original would just be a white document, obviously .

                When I use it as is, I open the document, enter in a hex code, fill in the corresponding rectangle with that color, and then take that color and darken it for a bit to use as the text color. And then I just repeat that. If you're asking about how I'd like the workflow if a script was created, I would just want to be able to edit the text layer, and for the rectangle and text color to use the information provided in the contents of the text layer to then edit themselves accordingly, with the rectangle matching that particular hex code, and the color of the text to be a darker shade than that of the hex code.

                • 5. Re: Color Comparison Script
                  pixxxel schubser MVP & Adobe Community Professional

                  You do not use your document as master document?

                  Your (end) files are all does have the same size?

                  The left and the right color are in relation?

                  • 6. Re: Color Comparison Script
                    Ethan J. Level 1

                    I'm not sure what you mean by "master document," but this is the only one. A copy can easily be made whenever necessary.

                    I export as JPG (usually) at maximum quality, which results in a 928 × 387 resolution.

                    The left and right color are completely independent of each other, the only colors in relation are that of the rectangle on the left and the text layer above it, and the similar counterparts on the right.

                    • 7. Re: Color Comparison Script
                      pixxxel schubser MVP & Adobe Community Professional

                      Master document means: you use this document always as template. Or do you always start with a new document?

                      • 8. Re: Color Comparison Script
                        Ethan J. Level 1

                        Ah, my apologies. Yes, this would just be a template.

                        • 9. Re: Color Comparison Script
                          r-bin Level 4

                          Try this simple script with your file, the link to which you posted

                           

                          activeDocument.activeLayer = activeDocument.layers[3];
                          var c = edit_solid_color();
                          
                          if (c) 
                              {
                              activeDocument.layers[1].textItem.contents = "#" + c.rgb.hexValue;
                          
                              c.lab.l = c.lab.l * 0.75;
                          
                              activeDocument.layers[1].textItem.color = c;
                          
                              activeDocument.activeLayer = activeDocument.layers[2];
                          
                              c = edit_solid_color();
                          
                              if (c) 
                                  {
                                  activeDocument.layers[0].textItem.contents = "#" + c.rgb.hexValue;
                          
                                  c.lab.l = c.lab.l * 0.75;
                          
                                  activeDocument.layers[0].textItem.color = c;
                                  }
                              }
                          
                          function edit_solid_color()
                              {
                              try {
                                  var r = new ActionReference();
                                  r.putEnumerated(stringIDToTypeID("contentLayer"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
                          
                                  var d = new ActionDescriptor();
                                  d.putReference(charIDToTypeID("null"), r);
                          
                                  d.putObject(stringIDToTypeID("to"), stringIDToTypeID("solidColorLayer"), new ActionDescriptor());
                                  d = executeAction(stringIDToTypeID("set"), d, DialogModes.ALL );
                          
                                  d = d.getObjectValue(stringIDToTypeID("to")).getObjectValue(stringIDToTypeID("color"));
                          
                                  var r = d.getDouble(stringIDToTypeID("red"));
                                  var g = d.getDouble(stringIDToTypeID("green"));
                                  var b = d.getDouble(stringIDToTypeID("blue"));
                          
                                  var c = new SolidColor; with (c.rgb) { red = r; green = g; blue = b; };
                          
                                  return c;
                                  }
                              catch(e) { return null; }
                              }   
                          
                          2 people found this helpful
                          • 10. Re: Color Comparison Script
                            pixxxel schubser MVP & Adobe Community Professional

                            Hi,

                            r-bin was faster.

                             

                             

                            Another way (but only for the right side) works also only with your Color Comparisons.psd

                            // required: Color Comparisons.psd
                            // regards pixxxel schubser
                            
                            var aDoc = activeDocument;
                            var hex = prompt ("please insert HEX value", "0000ff");
                            aDoc.activeLayer = aDoc.layers.getByName ("Rectangle 1 copy");
                            foregroundColor.rgb.hexValue = hex;
                            
                            var col = new SolidColor();
                            col = foregroundColor;
                            
                            var desc3 = new ActionDescriptor();
                                var ref1 = new ActionReference();
                                ref1.putEnumerated( sTID('contentLayer'), cTID('Ordn'), cTID('Trgt') );
                            desc3.putReference( cTID('null'), ref1 );
                                var desc4 = new ActionDescriptor();
                                    var desc5 = new ActionDescriptor();
                                    desc5.putDouble( cTID('Rd  '), col.rgb.red );
                                    desc5.putDouble( cTID('Grn '), col.rgb.green );
                                    desc5.putDouble( cTID('Bl  '), col.rgb.blue );
                                desc4.putObject( cTID('Clr '), cTID('RGBC'), desc5 );
                            desc3.putObject( cTID('T   '), sTID('solidColorLayer'), desc4 );
                            executeAction( cTID('setd'), desc3, DialogModes.NO );
                            
                            var col2  = new SolidColor();
                            col2 = col;
                            var colB = col.hsb.brightness;
                            
                            if (colB < 30.1 && colB < 70) {
                                col2.hsb.brightness = colB + 30;
                                } else {
                                    col2.hsb.brightness = colB - 30;
                                    } 
                            
                            var aLay = aDoc.layers[0]
                            aLay.textItem.color = col2;
                            aLay.textItem.contents = "#"+ hex;
                            
                            function cTID(s) { return app.charIDToTypeID(s); };
                            function sTID(s) { return app.stringIDToTypeID(s); };
                            

                             

                            Have fun