Detecting white/coloured pixels in a layer (and crop it without deleting the pixels) via script?
Hi everyone! I'm trying my best to write a javascript that checks the bounding box of a black and white matte (in therory it could also have different colours against black). After that it should crop the bounding box but still keep the pixels in the background.
I've found the croping code (https://stackoverflow.com/questions/64246854/crop-without-deleting-cropped-pixels-photoshop-extendscript), but for the colour selection I'm out of luck.
modified croping code:
crop({
left: matte-l,
top: matte-t,
right: matte-r,
bottom: matte-b,
deleteCropped: false
});
function crop(data)
{
if (data.deleteCropped == undefined) data.deleteCropped = true; // default value
var desc = new ActionDescriptor();
var descRectangle = new ActionDescriptor();
descRectangle.putUnitDouble(charIDToTypeID('Top '), charIDToTypeID('#Pxl'), data.top);
descRectangle.putUnitDouble(charIDToTypeID('Left'), charIDToTypeID('#Pxl'), data.left);
descRectangle.putUnitDouble(charIDToTypeID('Btom'), charIDToTypeID('#Pxl'), data.bottom);
descRectangle.putUnitDouble(charIDToTypeID('Rght'), charIDToTypeID('#Pxl'), data.right);
desc.putObject(charIDToTypeID('T '), charIDToTypeID('Rctn'), descRectangle);
desc.putUnitDouble( charIDToTypeID('Angl'), charIDToTypeID('#Ang'), 0.000000 );
desc.putBoolean(charIDToTypeID('Dlt '), data.deleteCropped);
executeAction(charIDToTypeID('Crop'), desc, DialogModes.NO);
} // end of crop()
Any ideas on how to achive this?
best regards,
Till
