Hello everyone!
I’m trying to create an automatic crop, but I can’t find the distance in pixels between the selection and the bottom edge. This is the code I found to get the values.
All the values return exact, but the (bottom) doesn’t return anything.
const app = require('photoshop').app;
const core = require('photoshop').core;
await core.executeAsModal(async () => {
const result = await require('photoshop').action.batchPlay(
[
{
_obj: 'get',
_target: [{ _property: 'selection' }, { _ref: 'document', _enum: 'ordinal', _value: 'targetEnum' }]
}
],
{ synchronousExecution: true }
);
if (result.length > 0 && result[0].selection) {
// Extraindo valores corretamente
const bounds = result[0].selection;
const left = bounds.left._value || 0;
const top = bounds.top._value || 0;
const right = bounds.right._value || 0;
const bottom = bounds.bottom._value || 0;
const docWidth = app.activeDocument.width;
const docHeight = app.activeDocument.height;
// Calculando distâncias até as bordas
const distancia = {
esquerda: left,
topo: top,
direita: docWidth - right,
baixo: docHeight - bottom
};
alert(`Distância da seleção até as bordas:\n
Esquerda: ${distancia.esquerda}px\n
Topo: ${distancia.topo}px\n
Direita: ${distancia.direita}px\n
Baixo: ${distancia.baixo}px`);
} else {
alert('Nenhuma seleção ativa encontrada.');
}
});