What's new

Baselining Images


OnasMura

New Member
Messages
3
Likes
0
Hi, this is a question for PS Super Experts (I would think so).

So here is a situation. I need a script to baseline* images. I have roughly 40k+ images that need to be baselined and doing this manually would take ages. So I need a script that would do this automatic. Let's say I have image that is 2000x2000px. Script should start checking at the bottom of canvas @ 2000px. Would check the whole row and if there are only white pixels would move on to the next row, like 1999px and check again if all pixels are white. If it finds pixel that is not white (in hex or rgb value) then it would know that this is the bottom of an actual image. I have added example below. Does anyone know if this is even possible?

P.S. Images inside white canvas are not in the same position.

Capture1.JPG


*Baseline - dropping images which is on a white background to the lowest point of canvas.
 

Paul MR

The Script Master
Messages
382
Likes
206
The Trim is doing what you were asking for in a script and no there is no tolerance.
Sometimes it is quicker doing things manually, if they are not white then that is what you have to do.
Checking each pixel would take hours, again making a selection of a row then checking the histogram would take a very long time!.

Here is some code that would trim the white off the bottom then using the width make it square.

Code:
#target photoshop;
app.bringToFront();

main();
function main(){
if(!documents.length) return;
try{
var doc = app.activeDocument;
app.displayDialogs = DialogModes.NO;
var strtRulerUnits = app.preferences.rulerUnits;
var strtTypeUnits = app.preferences.typeUnits;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
var FillColour = new SolidColor;
FillColour.rgb.hexValue = 'ffffff'; 
app.backgroundColor= FillColour;
doc.trim(TrimType.BOTTOMRIGHT,false,false,true,false);
doc.resizeCanvas(doc.width.value,doc.width.value, AnchorPosition.BOTTOMCENTER);
}catch(e){
}
finally{
app.preferences.rulerUnits = strtRulerUnits;
app.preferences.typeUnits = strtTypeUnits;
    };
};
 

Top