• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How can I automatically create a rectangular layer mask from an irregularly shaped selection?

New Here ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

I am trying to automatically crop images. The subject is on a white background and extends from the left edge of the image to the right. The top and bottom of the subject are within the frame. I need to crop a certain distance from the top and bottom of the subject and a predefined width that would be calculated from the height of the subject.

My current idea is to create a duplicate layer and run Threshold on it, which allows me to select the subject clearly. Once I have the subject selected I can use Image -> Crop to create the desired rectangle, but I can't figure out a way to create a mask from the irregularly selected subject. Does anyone know a way to take a selection and convert it to a rectangle? I hope this makes sense, I can try to explain better if not. Thanks.

--Chris

TOPICS
Actions and scripting

Views

743

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Apr 03, 2013 Apr 03, 2013

// make selection rectangular;

// 2013, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

try {

var theBounds = myDocument.selection.bounds;

var theArray = [[theBounds[0], theBounds[1]], [theBounds[2], theBounds[1]], [theBounds[2], theBounds[3]], [theBounds[0], theBounds[3]]];

myDocument.selection.select(theArray, SelectionType.REPLACE, 0, false);

}

catch (e) {}

};

Votes

Translate

Translate
Adobe
Community Expert ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

Even an irregularly shaped Selection has rectangular bounds.

And those values can be used to define the four corners of a rectangular selection with Selection.select().

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

// make selection rectangular;

// 2013, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

try {

var theBounds = myDocument.selection.bounds;

var theArray = [[theBounds[0], theBounds[1]], [theBounds[2], theBounds[1]], [theBounds[2], theBounds[3]], [theBounds[0], theBounds[3]]];

myDocument.selection.select(theArray, SelectionType.REPLACE, 0, false);

}

catch (e) {}

};

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

This worked perfectly, thank you!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 03, 2013 Apr 03, 2013

Copy link to clipboard

Copied

You’re welcome.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 01, 2023 Oct 01, 2023

Copy link to clipboard

Copied

LATEST

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines