3 Replies Latest reply on Aug 12, 2015 10:14 PM by pb4891

    how o change background color of an image using script?

    pb4891

      how o change background color of an image using script?

        • 1. Re: how o change background color of an image using script?
          pixxxel schubser MVP & Adobe Community Professional

          Hi @pb4891,

          please explain:

          - which scripting language?

          - only the background color itself?

          - or do you want to fill the canvas of the background layer?

          - do you always have a real background layer?

           

          But anyway - try this to change only the background color with javascript:

          // create a color of your choice
          var BGcolor = new SolidColor();
          BGcolor.rgb.red = 0;
          BGcolor.rgb.green = 0;
          BGcolor.rgb.blue = 255;
          
          // set your color as background color
          backgroundColor.rgb.hexValue = BGcolor.rgb.hexValue;
          

           

           

          And this will change the color of background layer:

          // BGcolor_fillBackgroundLayer.jsx
          // https://forums.adobe.com/message/7781601#7781601
          
          // required: an opened document
          // fill canvas with blue color - if background layer exists
          // regards pixxxelschubser
          
          // create a color of your choice
          var BGcolor = new SolidColor();
          BGcolor.rgb.red = 0;
          BGcolor.rgb.green = 0;
          BGcolor.rgb.blue = 255;
          
          // set your color as background color
          backgroundColor.rgb.hexValue = BGcolor.rgb.hexValue;
          
          // check if a real background layer exists and fill with your color
          var aDoc = app.activeDocument;
          var theLayers = aDoc.layers;
          aDoc.activeLayer = theLayers[theLayers.length-1];
          var aLayer = aDoc.activeLayer;
          
          if (aLayer.isBackgroundLayer) {
              app.activeDocument.selection.fill (backgroundColor, ColorBlendMode.NORMAL, 100, false);
              alert("Done")
              } else {
                  // here you could create a new background layer - instead of the alert
                  alert ("Sorry, but there is no background layer");
                  }
          

           

          Have fun

           

          • 2. Re: how o change background color of an image using script?
            Calin Bercea

            To add to this the code, what is need it to search to multiple images that are loaded in Photoshop ?