Hi
I want to build a script which can check a Photoshop file and :
- find black pixel
- for each black pixel, look for another black pixel within maximum distance of 5 pixels
- then draw a line between the two black pixels.
I wrote this script below (my first script ...), but it's VERY slow (and my final image is VERY big), I think because I test the colour for each pixel of the image.
So another solution would be to first select black pixel with magic wand, then the script save all coordinates of selected pixels, then my script wil test only this pixels (less than 1% of the pixels are black in my image).
Is it possible with JavaScript ?
Thank you for your response !
Marc
function main(){
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var myHeight = app.activeDocument.height;
var myWidth = app.activeDocument.width; // Find black pixelfor(var i=5; i<myWidth; i++) { for(var j=5; j<myHeight; j++) { activeDocument.colorSamplers.removeAll() var sampler = activeDocument.colorSamplers.add([new UnitValue (i, 'px'), new UnitValue (j, 'px')]); if (sampler.color.rgb.hexValue === "000000") { // For each black pixel, search another black pixel below left up to 5 pixels for (var m=i-5; m<i; m++) { for (var n=j+1; n<j+5; n++) { activeDocument.colorSamplers.removeAll() var test = activeDocument.colorSamplers.add([new UnitValue (m, 'px'), new UnitValue (n, 'px')]); if (test.color.rgb.hexValue === "000000") { // Then draw a black line between the two black pixels var FillColour = new SolidColor; FillColour.rgb.hexValue = '000000'; var ad=activeDocument; ad.selection.select([[m,n],[i,j],[m,n+1],[i,j+1]], SelectionType.REPLACE, 0, true); ad.selection.fill(FillColour); ad.selection.deselect() } } // For each black pixel, search another black pixel below right up to 5 pixels for (var m=i+1; m<i+5; m++) { for (var n=j; n<j+5; n++) { activeDocument.colorSamplers.removeAll() var test = activeDocument.colorSamplers.add([new UnitValue (m, 'px'), new UnitValue (n, 'px')]); if (test.color.rgb.hexValue === "000000") { // Then draw a black line between the two black pixels var FillColour = new SolidColor; FillColour.rgb.hexValue = '000000'; var ad=activeDocument; ad.selection.select([[i,j],[m,n],[m,n+1],[i,j+1]], SelectionType.REPLACE, 0, true); ad.selection.fill(FillColour); ad.selection.deselect() } } } } } }}}
main();