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

Script to resize a SELECTION to specific dimensions?

New Here ,
Sep 25, 2008 Sep 25, 2008

Copy link to clipboard

Copied

Sounds like it ought to be easy, but heck if I can figure out how to do it. Is there a way to run a CS3 Photoshop script that will resize a SELECTION (just part of an image, not the entire image) to a specific pixel size (ex. 100 x 150)? I know you can manually resize a selection to a specific PERCENTAGE of its original size, but my script has to automatically shrink image selections of all different sizes down to a given H x W.

Any ideas?
TOPICS
Actions and scripting

Views

2.4K

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
Adobe
Valorous Hero ,
Sep 26, 2008 Sep 26, 2008

Copy link to clipboard

Copied

Not good, but you could create a new document from the selection, resize and paste back into a new selection.

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 ,
Sep 26, 2008 Sep 26, 2008

Copy link to clipboard

Copied

If you can make copy of your selection contents then you could record with ScriptListener "New Layer Via Copy" then resize & move this layer. Not tried this.

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
Valorous Hero ,
Sep 26, 2008 Sep 26, 2008

Copy link to clipboard

Copied

You will have the same problem Mark as resize on layers is by percentage.
activeLayer.resize( [horizontal] [, vertical] [, anchor]);

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 ,
Sep 26, 2008 Sep 26, 2008

Copy link to clipboard

Copied

Paul, you are quite right bad me didn't look at the OP's question properly. Sorry. If you didn't want the new doc route you could save history step, crop to selection, resize canvas, copy, return to saved history state & paste? or at least I think you could.

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
Valorous Hero ,
Sep 26, 2008 Sep 26, 2008

Copy link to clipboard

Copied

LATEST
Yes that should work Mark, just being playing and this seems to work, needs a selection to be made and the layer must not be the background.
resizeSelection() is called using pixels.



resizeSelection(100,200);



/////////////////////////////////////////////////////////

//A selection must be made first

/////////////////////////////////////////////////////////

function resizeSelection(horizontal, vertical){

var strtRulerUnits = app.preferences.rulerUnits;

var strtTypeUnits = app.preferences.typeUnits;

app.preferences.rulerUnits = Units.PIXELS;

app.preferences.typeUnits = TypeUnits.PIXELS;

var SB = activeDocument.selection.bounds;

var Height = SB[3].value - SB[1].value;

var Width = SB[2].value - SB[0].value;

var onePixH = 100/Height;

var onePixW = 100/Width;

var newWidth = onePixW * horizontal;

var newHeight = onePixH * vertical;

activeDocument.selection.resize( newWidth , newHeight, AnchorPosition.MIDDLECENTER );

app.preferences.rulerUnits = strtRulerUnits;

app.preferences.typeUnits = strtTypeUnits;

}

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