Skip navigation
ginostylz
Currently Being Moderated

Photoshop Automation color replacement

Feb 17, 2012 2:28 PM

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.

 
Replies
  • Currently Being Moderated
    Feb 18, 2012 12:32 AM   in reply to ginostylz

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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 19, 2012 10:51 PM   in reply to ginostylz

    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, …?

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2012 6:28 AM   in reply to ginostylz

    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).

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2012 6:49 AM   in reply to ginostylz

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2012 7:08 AM   in reply to ginostylz

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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2012 7:32 AM   in reply to ginostylz

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2012 7:47 AM   in reply to ginostylz

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2012 7:58 AM   in reply to ginostylz

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2012 8:19 AM   in reply to WebNola

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2012 8:50 AM   in reply to WebNola

    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
            };
              };
    
     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2012 1:12 PM   in reply to c.pfaffenbichler

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2012 2:22 PM   in reply to WebNola

    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"));

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2012 3:03 PM   in reply to Muppet Mark

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 20, 2012 10:58 PM   in reply to WebNola

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 21, 2012 1:19 AM   in reply to WebNola

    resultingFiles2.jpg

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 21, 2012 8:02 PM   in reply to c.pfaffenbichler

    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!

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 21, 2012 11:17 PM   in reply to WebNola

    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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points