Accessing individual pixels of an image with Javascript

H
Posted By
Hitchkas
Sep 3, 2006
Views
419
Replies
1
Status
Closed
How one accesses individual pixels of an image in Javascript for PhotoShop? For example is there a method that allows something like the following?

//x, and y pixel coordinates along width and height of image Image.Channel.Red(x, y) = 128;

Namely, how one can read and write an individual pixel value of an image?

How to Master Sharpening in Photoshop

Give your photos a professional finish with sharpening in Photoshop. Learn to enhance details, create contrast, and prepare your images for print, web, and social media.

R
Ripley
Sep 4, 2006
found this somewhere:
//////////////////
var pixelColor = getPixelColor(100,100); // the two values are the horizontal and vertical position of the pixel you want the color from function getPixelColor(pixH,pixV){ // this only works for an active RGB document
var selRegion = null;
selRegion = Array(Array(pixH, pixV),
Array(pixH + 1, pixV),
Array(pixH + 1, pixV + 1),
Array(pixH, pixV + 1),
Array(pixH, pixV));
var currDoc = app.activeDocument;
currDoc.selection.select(selRegion);
var histR = currDoc.channels.getByName("Red").histogram; var histG = currDoc.channels.getByName("Green").histogram; var histB = currDoc.channels.getByName("Blue").histogram; var returnColor = new RGBColor();
for (iHistR in histR){
if(histR[iHistR]!=0){
returnColor.red = iHistR;
}
}
for (iHistG in histG){
if(histG[iHistG]!=0){
returnColor.green = iHistG;
}
}
for (iHistB in histB){
if(histB[iHistB]!=0){
returnColor.blue = iHistB;
}
}
return returnColor;
}
alert(pixelColor.hexValue+"\n"+pixelColor.red+","+pixelColor.green+ ","+pixel
Color.blue);
/////////////////////
and to fill that with new color:
var color = new SolidColor();
color.rgb["hexValue"] = "00ff00";
currDoc.selection.fill(color);

R

"Hitchkas" wrote in message
How one accesses individual pixels of an image in Javascript for PhotoShop? For example is there a method that allows something like the following?

//x, and y pixel coordinates along width and height of image Image.Channel.Red(x, y) = 128;

Namely, how one can read and write an individual pixel value of an image?

Master Retouching Hair

Learn how to rescue details, remove flyaways, add volume, and enhance the definition of hair in any photo. We break down every tool and technique in Photoshop to get picture-perfect hair, every time.

Related Discussion Topics

Nice and short text about related topics in discussion sections