Copy link to clipboard
Copied
how o change background color of an image using script?
Copy link to clipboard
Copied
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
![]()
Copy link to clipboard
Copied
To add to this the code, what is need it to search to multiple images that are loaded in Photoshop ?
Copy link to clipboard
Copied
Thanks for the code.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more