Copy link to clipboard
Copied
any one know of a good method to have PS eye dropper a known area of a bunch of images, and export that value out to a log or something? we have a bunch of images that should not have a white background but slightly off white, and its not something you can easily see visually but if i can script to measure all the same locations of every file it would be very clear which ones need to be updated.
Copy link to clipboard
Copied
Here's some bits I've made with feedback from different people on this forum, I hope it helps you along. 🙂
For the eye dropper part:
/**
* Returns the color on coordinate(x,y) as a SolidColor object.
* @param {number} x x-coordinate of the colorSampler as pixels
* @param {number} y y-coordinate of the colorSampler as pixels
* @return {SolidColor} Color information of that pixel
*/
getSolidColor = function(x, y) {
this.docRef.colorSamplers.removeAll();
/* The next 2 lines sanitize the x&y coordinate to be within the image bounds
* and takes care of the colorsampler bug that rounds down a number to aggressively
*/
x = (x < this.docRef.width) ? x+0.1 : this.docRef.width-1;
y = (y < this.docRef.height) ? y+0.1 : this.docRef.height-1;
this.docRef.colorSamplers.add( [parseInt(x), parseInt(y) ] );
var solidClr = this.docRef.colorSamplers[0].color;
this.docRef.colorSamplers.removeAll();
return solidClr;
};
/* To use the function: */
alert("Add your solidcolor property of choice here: ", getSolidColor(2,3));
After which, this thingamabob writes a line to a file:
/**
* writes a message to a target file
* @param {string} message The message to log to a file
* @param {path} logFile The location of the file
* @param {boolean} timestamp If true, prefixes a timestamp to the message
*/
logLn = function(message,logFile, timestamp) {
var lf = File(logFile);
lf.open("a",undefined,undefined);
lf.encoding = "UTF-8";
if(timestamp){
lf.writeln(File.decode(now = new Date()+" : " + message));
} else {
lf.writeln(File.decode(message));
}
lf.close();
};
/* To use the function: */
logLn("I'm a little teapot", "c:\log.txt", true);
Apart from handling the images, these 2 functions should get you a long way I think.
All the best!
Copy link to clipboard
Copied
»to measure all the same locations of every file«
Please explain what this is intended to describe; do you want to get a measurement for the exact same position in all images, multiple positions, …?
Copy link to clipboard
Copied
Yes. i'd like to pick a known location X,Y in a series of files, and measure that location RGB value and export out all the values to a file. once thats done i'm gong to add it as an IF statment to check every file before saying that it matches the set value.
Copy link to clipboard
Copied
This should create a txt-file based on all the open documents.
// 2020, use it at your own risk;
if (app.documents.length > 0) {
// get start time;
var theDocs = app.documents;
var time1 = Number(timeString());
// create file;
var a = new File("~/Desktop/test.txt");
// open file;
a.open('w');
// move color sampler;
for (var y = 0; y < theDocs.length; y++) {
app.activeDocument = theDocs[y];
app.activeDocument.colorSamplers.removeAll();
var theSampler = app.activeDocument.colorSamplers.add([9.5,9.5]);
a.write(Math.round(theSampler.color.rgb.red) + "," + Math.round(theSampler.color.rgb.green) + "," + Math.round(theSampler.color.rgb.blue) + ";");
};
a.close();
// get end time;
var time2 = Number(timeString());
alert(((time2-time1)/1000)+" seconds\nstart "+time1+"\nend "+time2);
};
////// function to get the date //////
function timeString () {
var now = new Date();
return now.getTime()
};
Copy link to clipboard
Copied
Ah, I forgot to have the Script write anything but the color values in the txt-file … but you can easily add the documents’ names or fullNames in the txt-file by modifying the line
a.write(…
Copy link to clipboard
Copied
Thank you. i assume that the snippet from below is determining where on the document to sample from, but i don't understand how to change that to a specific location? what is 9.5, 9.5 in realtion to the activateDocument canvas?
var theSampler = app.activeDocument.colorSamplers.add([9.5,9.5]);
Copy link to clipboard
Copied
Yeah, sloppy scripting … I should have included the line
app.preferences.rulerUnits = Units.PIXELS;
at the beginning.
Then it’s pixels and the 0.5 added means that the middle of the pixel gets measured and not the point where pixels meet,
Copy link to clipboard
Copied
But the measured result would still depend on the Sample Size of the Eyedropper Tool, if I remember correctly.
Copy link to clipboard
Copied
@pfaffenbichler: Your Eyedropper sample size comment made me think about jpeg artefacts...
@bflieck: From how I interpret our thread, you're going to go over the results manually, you might see variance in the values that are caused by jpg artefacting. The measurements might be less than 100% reliable.
Depending on how much accuracy you need, if you are able to account for the artefacting, the measurements could also be used to move your files into 2 folders for you...
Copy link to clipboard
Copied
Easy way to check for white background-
Create a Levels adjustment layer. Drag the black slider all the way to the right (253.) Duplicate that layer.
It will be VERY obvious if there are any non-255 pixels.