Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

182
Visualizações
Photoshop scripting circular selection on new layer

I'm trying to dynamically add layers in a Photoshop script via JavaScript. The layers have a circular selection, not rectangular or triangular.

For example rectangular:

var RectangleSelection = Array(
   Array(x, y), // start position
   Array(x + width, y), // right top
   Array(x + width, y + height), // right bottom            
   Array(x, y + height), // left bottom
   Array(x, y) // left top
);

I want to do the same now with a circular selection, maybe with a function like this? I'm stuck how to define the function:

var circleSelection = makeCircleSelection(x,y,radius); 

And return it in a selection which I can then place on a new layer:

var layer = document.artLayers.add();
document.selection.select(circleSelection);
document.selection.copy();
document.paste();

The docs don't have an answer and this answer I find difficult for my use case.

Thank you very much!

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You can utilize the following custom makeCircleSelection function. As you can see its signature has three parameters, namely x, y and radius.

/**
 * Make a circular selection.
 * @param {Number} x The center of the circular selection on the x-axis.
 * @param {Number} y The center of the circular selection on the y-axis.
 * @param {Number} radius The radius of the circular selection.
 * @returns {Object} A reference to the newly created circular selection.
 */
function makeCircleSelection(x, y, radius) {
  var d1 = new ActionDescriptor();
  var d2 = new ActionDescriptor();
  var ref = new ActionReference();

  d1.putUnitDouble(charIDToTypeID('Top '), charIDToTypeID('#Pxl'), y - radius);
  d1.putUnitDouble(charIDToTypeID('Left'), charIDToTypeID('#Pxl'), x - radius);
  d1.putUnitDouble(charIDToTypeID('Btom'), charIDToTypeID('#Pxl'), y + radius);
  d1.putUnitDouble(charIDToTypeID('Rght'), charIDToTypeID('#Pxl'), x + radius);

  ref.putProperty(charIDToTypeID('Chnl'), charIDToTypeID('fsel'));

  d2.putReference(charIDToTypeID('null'), ref);
  d2.putObject(charIDToTypeID('T   '), charIDToTypeID('Elps'), d1);
  d2.putUnitDouble(charIDToTypeID('Fthr'), charIDToTypeID('#Pxl'), 0);
  d2.putBoolean(charIDToTypeID('AntA'), true);

  executeAction(charIDToTypeID('setd'), d2, DialogModes.NO);
  return document.selection;
}

Then you can do the following to meet your requirement:

// Example usage

var document = app.activeDocument;

var circleSelection = makeCircleSelection(200, 100, 100);
circleSelection.copy();

document.artLayers.add();
document.paste();

Note: You'll need to ensure that pixels exist within the circular selection on the active art layer that you copy from. The area cannot be transparent.

about 4 years ago · Juan Pablo Isaza Relatório

0

Thanks for answering my question! The solution works perfect.

If you want follow me on instagram.

I'll definitely use the code for my digital art project.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda