var cOutput = 127
var cPoints = new Array(Array(0,0), Array(127, cOutput), Array(255,255));
app.activeDocument.activeLayer.adjustCurves(cPoints);
getColorAt = function(doc, x, y) {
function selectBounds(doc, b) {
doc.selection.select([[ b[0], b[1] ],
[ b[2], b[1] ],
[ b[2], b[3] ],
[ b[0], b[3] ]]);
}
function findPV(h) {
for (var i = 0; i <= 255; i++ ) { if (h[i]) { return i; } } return 0; }
selectBounds(doc, [x, y, x+1, y+1]);
var pColour = new SolidColor();
pColour.rgb.red = findPV(doc.channels["Red"].histogram);
pColour.rgb.green = findPV(doc.channels["Green"].histogram);
pColour.rgb.blue = findPV(doc.channels["Blue"].histogram);
doc.selection.deselect(); // or, even better, undo
};
// Save the current preferences
var startRulerUnits = app.preferences.rulerUnits
var startTypeUnits = app.preferences.typeUnits
var startDisplayDialogs = app.displayDialogs
var docRef = app.activeDocument;
var activeChannels = docRef.activeChannels;
// Set Adobe Photoshop CS2 to use pixels and display no dialogs
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
app.displayDialogs = DialogModes.NO
// prompt("Define XY in pixels", 0, "Get Color Sample");
var x = 550;
var y = 100;
for (var i = 0; i < docRef.channels.length; i++) {
docRef.channels[i].visible = true;
// turn OFF all channels except current
for (var j = 0; j < docRef.channels.length; j++) {
if (i != j) {docRef.channels[j].visible = false;}
}
docRef.activeChannels = Array(docRef.channels[i]);
selectBounds(docRef, [x, y, x+1, y+1]);
var cOutput = findPV(docRef.channels[i].histogram);
// alert(docRef.channels[i].name + " " + cOutput);
docRef.selection.deselect();
var cPoints = new Array(Array(0,0), Array(cOutput, 127), Array(255,255));
docRef.activeLayer.adjustCurves(cPoints);
}
// Reset the application preferences
app.preferences.rulerUnits = startRulerUnits
app.preferences.typeUnits = startTypeUnits
app.displayDialogs = startDisplayDialogs
docRef.activeChannels = activeChannels;
function selectBounds(doc, b) {
doc.selection.select([[ b[0], b[1] ],
[ b[2], b[1] ],
[ b[2], b[3] ],
[ b[0], b[3] ]]);
}
function findPV(h) {
for (var i = 0; i <= 255; i++ ) {
if (h[i]) { return i; }
}
return 0;
}
// Save the current preferences
var startRulerUnits = app.preferences.rulerUnits
var startDisplayDialogs = app.displayDialogs
var docRef = app.activeDocument;
var activeChannels = docRef.activeChannels;
// Set Adobe Photoshop CS2 to use pixels and display no dialogs
app.preferences.rulerUnits = Units.PIXELS
app.displayDialogs = DialogModes.NO
var cInput = new Array();
var cOutput = 0;
var cLength = docRef.channels.length;
// prompt("Define XY in pixels", 0, "Get Color Sample");
var x = 550;
var y = 100;
// make selection 1X1 pixel by X and Y
selectBounds(docRef, [x, y, x+1, y+1]);
// collect the pixel value in all channels and calculate brightness
for (var i = 0; i < cLength; i++) {
docRef.channels[i].visible = true;
// turn OFF all channels except current
for (var j = 0; j < docRef.channels.length; j++) {
if (i != j) {docRef.channels[j].visible = false;}
}
cInput[i] = findPV(docRef.channels[i].histogram);
cOutput += (cInput[i] / cLength);
}
// deselect pixel
docRef.selection.deselect();
docRef.activeChannels = activeChannels;
// adjust per channel
for (var i = 0; i < cInput.length; i++) {
docRef.channels[i].visible = true;
// turn OFF all channels except current
for (var j = 0; j < docRef.channels.length; j++) {
if (i != j) {docRef.channels[j].visible = false;}
}
docRef.activeChannels = Array(docRef.channels[i]);
var cPoints = new Array(Array(0,0), Array(cInput[i], cOutput), Array(255,255));
docRef.activeLayer.adjustCurves(cPoints);
}
// Reset the application preferences
app.preferences.rulerUnits = startRulerUnits
app.displayDialogs = startDisplayDialogs
docRef.activeChannels = activeChannels;
function selectBounds(doc, b) {
doc.selection.select([[ b[0], b[1] ],
[ b[2], b[1] ],
[ b[2], b[3] ],
[ b[0], b[3] ]]);
}
function findPV(h) {
for (var i = 0; i <= 255; i++ ) {
if (h[i]) { return i; }
}
return 0;
}
////оpen an ini file
var fileRef = new File ("/c/temp/save_text_jpeg.ini/");
fileRef.open ("r:");
var b = fileRef.read ();
//set up dialogmode
app.displayDialogs = DialogModes.NO;
//determine if a top layer object is a layer or a layerset
//in case of being a layerset select it's top layer as an active layer
//otherwise select a top layer object as an active layer
var y = app.activeDocument.layers [0];
var x = app.activeDocument.layerSets [0];
if ( y ==x) {
app.activeDocument.activeLayer = x.layers [0]
} else {
app.activeDocument.activeLayer = y};
//read the text content of an active layer
var x = app.activeDocument.activeLayer.textItem.contents;
//save the file as jpeg
var OutputFolder = b
//********* начало вставки *****************************
var jpegOptions = new JPEGSaveOptions();
jpegOptions.quality = 8;
//********* конец вставки *****************************
//********* ниже JPEGSaveOptions изменено на jpegOptions ********
app.activeDocument.saveAs (new File (OutputFolder + "/" + x +".jpg"), jpegOptions)
app.activeDocument.saveAs (new File (OutputFolder + "/" + x +".jpg"), jpegOptions)
var s = OutputFolder + "/" + x +".jpg";
for (var j = 0; j < 10; j++ ) {
if ( j > 0 ) { var f = newFile ("copy(" + j + ")" + s); } else { var f = newFile (s); }
if ( f.exists == false ) { break; }
};
app.activeDocument.saveAs (f, jpegOptions);