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

Need to combine two scripts, enacting second upon checking height.

New Here ,
Sep 10, 2018 Sep 10, 2018

Copy link to clipboard

Copied

Hello, apologies for JavaScript illiteracy and the need for help.

In creating an action to size (by pixel) and position a layer, I happened upon this awesome script here (shown below): Action records layer transform in percentage NOT pixels???

I use this script to resize to 2400 pixels wide, while constraining proportions. For most graphics, this is fine and does the job. My problem is that my end-product cannot be greater than 3210px in height and very once in a while I have a tall and narrow graphic. I need to somehow alter this script to check the height after resizing, and if it is greater than 3210, then to instead resize (constraining proportions) to a height of 3210.

Script I'm using to make layer graphic 2400 pixels wide

#target photoshop

function main(){

if(!documents.length) return;

var startRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

var doc = activeDocument;

var res= doc.resolution;

var LB = activeDocument.activeLayer.bounds;

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

var onePix = 100/Width;

var newSize = onePix * 2400;

doc.activeLayer.resize( newSize , newSize, AnchorPosition.MIDDLECENTER);

app.preferences.rulerUnits = startRulerUnits;

}

main();

I just need some help with how to put in the If/Then logic.

So, if it finishes that, and the height is greater than 3210, then it should probably do this:

Height resize script

#target photoshop

function main(){

if(!documents.length) return;

var startRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

var doc = activeDocument;

var res= doc.resolution;

var LB = activeDocument.activeLayer.bounds;

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

var onePix = 100/Height;

var newSize = onePix * 3210;

doc.activeLayer.resize( newSize , newSize, AnchorPosition.MIDDLECENTER);

app.preferences.rulerUnits = startRulerUnits;

}

main();

TOPICS
Actions and scripting

Views

237

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
People's Champ ,
Sep 10, 2018 Sep 10, 2018

Copy link to clipboard

Copied

LATEST

function main()

    {

    if(!documents.length) return;

    var startRulerUnits = app.preferences.rulerUnits;

    app.preferences.rulerUnits = Units.PIXELS;

    var doc = activeDocument;

    var LB = activeDocument.activeLayer.bounds;

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

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

    var onePix = 100/Width;

    var newSize = onePix * 2400;

    var newHeight = newSize/100 * Height;

    if (newHeight > 3210) newSize = 100/Height * 3210;

    doc.activeLayer.resize(newSize , newSize, AnchorPosition.MIDDLECENTER);

    app.preferences.rulerUnits = startRulerUnits;

    }

main();

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