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?

Must-have mockup pack for every graphic designer 🔥🔥🔥

Easy-to-use drag-n-drop Photoshop scene creator with more than 2800 items.

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?

How to Improve Photoshop Performance

Learn how to optimize Photoshop for maximum speed, troubleshoot common issues, and keep your projects organized so that you can work faster than ever before!

Related Discussion Topics

Nice and short text about related topics in discussion sections