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

Select Crop Tool and select a ratio (based on Filename)

Contributor ,
May 24, 2016 May 24, 2016

I have lots of files that when I crop them they need to a specific ratio. Currently they are saved to the tool.

I would like to be able to make a shortcut so that it selects the crop tool and selects the ratio from the File name. I can gather the info from the filename.

i.e.  FR10 = a Ratio of 2:3

or

DE20 = 3:4

It does not need to crop the image just select the tool.

I found this to select the tool

The beginning is like this.

if (app.documents.length > 0) {

    var myDocument = activeDocument;

    var fileNameNoExtension = myDocument.name;

   

  fileNameNoExtension = fileNameNoExtension.split( "." );

   

  if ( fileNameNoExtension.length > 1 ) {

      fileNameNoExtension.length--;

    }

    fileNameNoExtension = fileNameNoExtension.join(".");

   

    var BrandString = fileNameNoExtension.substr(0,4);

 

  }

if (/^(FR10|WA35)$/.exec(BrandString)){

    var the_x_Ratio =2

    var the_y_Ratio =3

    }

TOPICS
Actions and scripting
3.7K
Translate
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 , May 25, 2016 May 25, 2016

// 2016, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

var width = myDocument.width;

var height = myDocument.height;

var rel = 1;

if (myDocument.name.indexOf("AB10") != -1) {var rel = 0.666};

if (myDocument.name.indexOf("CD10") != -1) {var rel = 0.75};

if (myDocument.name.indexOf("EF10") != -1) {var rel = 0.8};

if (myDocument.name.indexOf("CH10") !

...
Translate
Adobe
Contributor ,
Jun 14, 2016 Jun 14, 2016

OK So I have popped this into the top of the original script 

var ref = new ActionReference();

ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

var applicationDesc = executeActionGet(ref);

var currentToolOpt = applicationDesc.getObjectValue(stringIDToTypeID("currentToolOptions"));

var settings = currentToolOpt.getObjectValue(currentToolOpt.getKey(0));

var previouswidth (settings.getUnitDoubleValue(settings.getKey(3)));

var previousheight (settings.getUnitDoubleValue(settings.getKey(5)));

Then after all my if statements added the else like lie so,

if (myDocument.name.indexOf("WA35") != -1) {var rel = (2/3)};

if (myDocument.name.indexOf("MM__") != -1) {var rel = (1500/2000)};

else {var rel = (previouswidth/previousheight)};

Obviously not working how do I write the else if nothing fits then use previous?

Translate
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 ,
Jun 14, 2016 Jun 14, 2016

Why keys 3 and 5?

Don’t you need 1 and 2?

Translate
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
Contributor ,
Jun 14, 2016 Jun 14, 2016

3 and 5 match those entered in the ratio.

Screen Shot 2016-06-14 at 13.55.31.png

Translate
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
Contributor ,
May 16, 2017 May 16, 2017

I would like to know if it is possible to have the 16x9 ratio

Schermata 2017-05-16 alle 19.37.22.png

Translate
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
Contributor ,
May 25, 2017 May 25, 2017

No one can help me with the horizontal crop

Translate
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 ,
May 25, 2017 May 25, 2017

No one can help me with the horizontal crop

What is the problem?

Have you tried amending the Script?

Translate
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
Contributor ,
May 25, 2017 May 25, 2017

I did various tests but I did not have any luck

I would like the crop to be horizontal as in the figure above

thank you

Translate
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 ,
May 25, 2017 May 25, 2017
LATEST

Quite frankly I think you should start a new thread and post the code you have issues with instead of adding to some old thread.

Translate
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