What's new

Issue with Batch processing and Actions


Messages
5
Likes
0
So I have a bunch of PSD files that I'm trying to resize and expand the background. The backgrounds are solid colors. The issue that I'm having is that the background layers are not named the same or the files don't have the same amount of layer.

When I go to expand the canvas size I want it to match the same color as the background. Here are my current actions list.

1. Image Size (reduced)
2. Merge Visible Layers
3. Canvas Size (Larger)

Here is where I get stuck. I want to fill the transparent canvas with the same color as the background but if I use the eye dropper tool it will do that one color. For example if one picture has a black background and I use that one to create my actions. When batch processing it will use the black color on the other files even if they have a blue background.

I need way to select the current color of the file that it's processing to fill the expanded canvas.


Any help would be greatly appreciated.

Thanks
 

revnart

Power User
Messages
361
Likes
323
And no matter which image background is always solid color? If so I will have a solution ;)
Second question - is every image have to be resized my same amount or to match specific size?
 

revnart

Power User
Messages
361
Likes
323
Just came with, probably simplest solution if background layer is solid color ;)

1. open your image
2. change canvas size
3. using shortcut Alt+, select most bottom layer (its important to not select by mouse)
3B. if this layer is "Fill Layer" rasterize it
4. use ctrl+T and transform it much bigger than canvas
5. Merge Visible

Hope that helps, it would be easier If I could see example of your psd :)
 
Messages
5
Likes
0
3. using shortcut Alt+, select most bottom layer (its important to not select by mouse)
4. use ctrl+T and transform it much bigger than canvas

This help me get what I needed to get done.

Thanks
 

revnart

Power User
Messages
361
Likes
323
Glad you we found solution ;) If you will find yourself in a situation where you will have to "pick color" instead of transforming layer here is the script that picks top-left pixel color and sets it as background color sample:

JavaScript:
var myDoc = app.activeDocument;

var docWidth = myDoc.width;
var docHeight = myDoc.height;
var xPos = 0;
var yPos = 0;

app.activeDocument.colorSamplers.removeAll();
var target = [UnitValue(0) , UnitValue(0)];
var sample = app.activeDocument.colorSamplers.add(target);

var Color = sample.color;
var R = Math.ceil(Color.rgb.red);
var G = Math.ceil(Color.rgb.green);
var B = Math.ceil(Color.rgb.blue);

app.activeDocument.colorSamplers.removeAll();

var color = app.backgroundColor;
color.rgb.red = R;
color.rgb.green = G;
color.rgb.blue = B;

app.backgroundColor = color;
just paste it in the notepad and save as file with .jsx extension
 
Messages
5
Likes
0
Glad you we found solution ;) If you will find yourself in a situation where you will have to "pick color" instead of transforming layer here is the script that picks top-left pixel color and sets it as background color sample:

JavaScript:
var myDoc = app.activeDocument;

var docWidth = myDoc.width;
var docHeight = myDoc.height;
var xPos = 0;
var yPos = 0;

app.activeDocument.colorSamplers.removeAll();
var target = [UnitValue(0) , UnitValue(0)];
var sample = app.activeDocument.colorSamplers.add(target);

var Color = sample.color;
var R = Math.ceil(Color.rgb.red);
var G = Math.ceil(Color.rgb.green);
var B = Math.ceil(Color.rgb.blue);

app.activeDocument.colorSamplers.removeAll();

var color = app.backgroundColor;
color.rgb.red = R;
color.rgb.green = G;
color.rgb.blue = B;

app.backgroundColor = color;
just paste it in the notepad and save as file with .jsx extension

Hello,

This worked great. I have some images that have black line bordering the image. So it's making the background black instead of the background color of the image. How can I change the code to move the position of the sample color just a few pixels into the image? I tried to change xPos and yPos numbers but that didn't help.
 

ph_o_e_n_ix

Well-Known Member
Messages
119
Likes
133
JavaScript:
#target photoshop

var aDoc = app.activeDocument;

var xPos = 2;
var yPos = 2;

aDoc.colorSamplers.removeAll();
var target = [UnitValue(xPos+0.5, "px"), UnitValue(yPos+0.5, "px")];
var sample = aDoc.colorSamplers.add(target);

var Color = sample.color;
var R = Math.ceil(Color.rgb.red);
var G = Math.ceil(Color.rgb.green);
var B = Math.ceil(Color.rgb.blue);

aDoc.colorSamplers.removeAll();

var color = app.backgroundColor;
color.rgb.red = R;
color.rgb.green = G;
color.rgb.blue = B;

app.backgroundColor = color;
 
Last edited:

revnart

Power User
Messages
361
Likes
323
Hey, here is fixed code ;)
JavaScript:
var doc = app.activeDocument;

//SAVE RULER UNITS
backupRuler = app.preferences.rulerUnits;

//SET RULERS TO PX
app.preferences.rulerUnits = Units.PIXELS;

//SET POSITION OF SAMPLE
var xPos = 5;
var yPos = 5;

//REMOVE EXISTING SAMPLES
app.activeDocument.colorSamplers.removeAll();

//SET NEW SAMPLE
var target = [xPos , yPos];
var sample = app.activeDocument.colorSamplers.add(target);

//GET COLORS FROM SAMPLE
var Color = sample.color;
var R = Math.ceil(Color.rgb.red);
var G = Math.ceil(Color.rgb.green);
var B = Math.ceil(Color.rgb.blue);

//REMOVE SAMPLE
app.activeDocument.colorSamplers.removeAll();

//SET NEW COLOR
var color = app.backgroundColor;
color.rgb.red = R;
color.rgb.green = G;
color.rgb.blue = B;

app.backgroundColor = color;

//RESTORE RULER SETTINGS
app.preferences.rulerUnits = backupRuler
 

ph_o_e_n_ix

Well-Known Member
Messages
119
Likes
133
@revnart

Don't sample the top left corner of a pixel - Photoshop has a known bug that sometimes causes one of the adjacent color values to be used.
 

revnart

Power User
Messages
361
Likes
323
@ph_o_e_n_ix

hey :) Never occured to me but, thanks :) Good to know, script allows to change x,y position easily.
Probably it's also good to test it with sample size values in that situation
 

ph_o_e_n_ix

Well-Known Member
Messages
119
Likes
133
Maybe you never even noticed because the adjacent pixels were similar colors?

Somewhere there was a small script and a sample file that could even be used to prove it - unfortunately I can no longer find the page.

Now our scripts only need to be interested in @Pimpdaddyfatsac ...
 

Top