Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

117
Views
Photoshop script to crop into square based on active selection

I’m trying to find Java script for photoshop, that will crop to a square based on selection, preserving resolution of the image Selections are irregular

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

This is very easy and a perfectly valid question. PhotoShop can crop to selection with a function.

cropToSelection();


// crop to selection
function cropToSelection()
{
  executeAction( charIDToTypeID( "Crop" ), new ActionDescriptor(), DialogModes.NO );
}

But if you want the selection bounds coordinates then use:

var lb = get_selection_bounds();

// alerts current selection bounds
alert(lb[0] + ", " + lb[1] + ", " + lb[2] + ", " + lb[3] );


// function GET SELECTION BOUNDS ()
// ----------------------------------------------------------------
function get_selection_bounds()
{
  // Only works with a selection
  var x = parseFloat(app.activeDocument.selection.bounds[0]);
  var y = parseFloat(app.activeDocument.selection.bounds[1]);
  var x1 = parseFloat(app.activeDocument.selection.bounds[2]);
  var y1 = parseFloat(app.activeDocument.selection.bounds[3]);

  // return the results as an array
  return [x, y, x1, y1];
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!