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

Scripting Fit Image Command

New Here ,
Jul 01, 2012 Jul 01, 2012

Copy link to clipboard

Copied

Does anyone know if there is a way to add the "Fit Image" command to a script?

This is what I currently am working with below. I just want to be able to make it so that images are no longer than 1000 pixels on either side, and not have to call an action.

Thanks!

Janice

//PLACE WATERMARK NOTICE IN FILE

var idPlc = charIDToTypeID( "Plc " );

    var desc973 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

    desc973.putPath( idnull, new File( "C:/watermark.gif\/" ) );

    var idFTcs = charIDToTypeID( "FTcs" );

    var idQCSt = charIDToTypeID( "QCSt" );

    var idQcsa = charIDToTypeID( "Qcsa" );

    desc973.putEnumerated( idFTcs, idQCSt, idQcsa );

    var idOfst = charIDToTypeID( "Ofst" );

        var desc974 = new ActionDescriptor();

        var idHrzn = charIDToTypeID( "Hrzn" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc974.putUnitDouble( idHrzn, idPxl, 0.000000 );

        var idVrtc = charIDToTypeID( "Vrtc" );

        var idPxl = charIDToTypeID( "#Pxl" );

        desc974.putUnitDouble( idVrtc, idPxl, 0.000000 );

    var idOfst = charIDToTypeID( "Ofst" );

    desc973.putObject( idOfst, idOfst, desc974 );

executeAction( idPlc, desc973, DialogModes.NO );

//FLATTEN IMAGE

app.activeDocument.mergeVisibleLayers()

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

correct answers 1 Correct answer

Community Expert , Jul 01, 2012 Jul 01, 2012

You could try this:

// make document square with the document’s longer side’s length;

// 2012, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var originalRulerUnits = preferences.rulerUnits;

preferences.rulerUnits = Units.PIXELS;

// get longer side;

var theFactor = 1000 / getTheLonger(Number(myDocument.width), Number(myDocument.height));

// resize;

myDocument.resizeImage (myDocument.width * theFactor, myDocument.height * theFactor, myDocumen

...

Votes

Translate

Translate
Adobe
Community Expert ,
Jul 01, 2012 Jul 01, 2012

Copy link to clipboard

Copied

You could try this:

// make document square with the document’s longer side’s length;

// 2012, use it at your own risk;

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var originalRulerUnits = preferences.rulerUnits;

preferences.rulerUnits = Units.PIXELS;

// get longer side;

var theFactor = 1000 / getTheLonger(Number(myDocument.width), Number(myDocument.height));

// resize;

myDocument.resizeImage (myDocument.width * theFactor, myDocument.height * theFactor, myDocument.resolution, ResampleMethod.BICUBIC);

// reset;

preferences.rulerUnits = originalRulerUnits;

}

else {};

function getTheLonger(a,b) {

          if (a >= b) {

                    var x = a}

          else {

                    var x = b};

          return x;

          };

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 ,
Jul 02, 2012 Jul 02, 2012

Copy link to clipboard

Copied

You can also look at the Image Processor script to see how it actually uses the Plug-in script "Fit Image.jsx"..   It woul look somethimg like this

FitImage( 1000, 1000 );

//Code below from "Image Processor.jsx"

// use the fit image automation plug-in to do this work for me

function FitImage( inWidth, inHeight ) {

          if ( inWidth == undefined || inHeight == undefined ) {

                    alert( strWidthAndHeight );   //This statement woul need to changed

                    return;

          }

          var desc = new ActionDescriptor();

          var unitPixels = charIDToTypeID( '#Pxl' );

          desc.putUnitDouble( charIDToTypeID( 'Wdth' ), unitPixels, inWidth );

          desc.putUnitDouble( charIDToTypeID( 'Hght' ), unitPixels, inHeight );

          var runtimeEventID = stringIDToTypeID( "3caa3434-cb67-11d1-bc43-0060b0a13dc4" );

          executeAction( runtimeEventID, desc, DialogModes.NO );

}

The image process set vars for localization

          // the string that need localized

          strWidthAndHeight = localize( "$$$/JavaScripts/ImageProcessor/WidthAndHeight=Width and Height must be defined to use FitImage function!" );1

JJMack

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
Guru ,
Jul 02, 2012 Jul 02, 2012

Copy link to clipboard

Copied

FIt Image itself is a script. You could have a look at it and copy the parts you need into your script. Or because that script is set up to work with actons you could use it as the Image Processor script does as JJMack suggested. Or as it looks like you are already using the scriptlistener plugin you could just do a FIt Image in the GUI and copy out the last entry in the log.

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 ,
Jul 02, 2012 Jul 02, 2012

Copy link to clipboard

Copied

LATEST

Thanks everyone!

The script from c.pfaffenbichler works.. and thanks again for all of the other advice.

Janice

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