Copy link to clipboard
Copied
DO NOT TRY THIS AT HOME!
In trying to script a transform that uses wither bicubic automatic or neares tneighbour transforms I managed to crash Photoshop with a script:
It creates a new document, with a new layer and then transforms it down 90% by either bicubic automatic (works fine) or Nearest Neighbour - Crash!
// USE THIS SCRIPT AT YOUR OWN RISK
// SAVE AND CLOSE ALL PHOTOSHOP DOCUMENTS
// YOU HAVE BEEN WARNED!!!
displayDialogs = DialogModes.ERROR; // OFF
var docRef = app.documents.add(20, 20, 72, "temp");
srcDoc = app.activeDocument;
duplicate_layer("temp");
transform_by_type("Nrst") // THIS WILL CRASH PHOTOSHOP
function transform_by_type(transformtype)
{
// =======================================================
var idTrnf = charIDToTypeID( "Trnf" );
var desc5623 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref1379 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref1379.putEnumerated( idLyr, idOrdn, idTrgt );
desc5623.putReference( idnull, ref1379 );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc5623.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc5624 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5624.putUnitDouble( idHrzn, idPxl, -0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc5624.putUnitDouble( idVrtc, idPxl, -0.000000 );
var idOfst = charIDToTypeID( "Ofst" );
desc5623.putObject( idOfst, idOfst, desc5624 );
var idWdth = charIDToTypeID( "Wdth" );
var idPrc = charIDToTypeID( "#Prc" );
desc5623.putUnitDouble( idWdth, idPrc, 90.000000 );
var idHght = charIDToTypeID( "Hght" );
var idPrc = charIDToTypeID( "#Prc" );
desc5623.putUnitDouble( idHght, idPrc, 90.000000 );
var idIntr = charIDToTypeID( "Intr" );
var idIntp = charIDToTypeID( "Intp" );
var idTransform = stringIDToTypeID( transformtype );
desc5623.putEnumerated( idIntr, idIntp, idTransform );
executeAction( idTrnf, desc5623, DialogModes.NO );
}
// function DUPLICATE LAYER (str)
// --------------------------------------------------------
function duplicate_layer(str)
{
// duplicate layer normaly
// =======================================================
var id1572 = charIDToTypeID( "Dplc" );
var desc350 = new ActionDescriptor();
var id1573 = charIDToTypeID( "null" );
var ref184 = new ActionReference();
var id1574 = charIDToTypeID( "Lyr " );
var id1575 = charIDToTypeID( "Ordn" );
var id1576 = charIDToTypeID( "Trgt" );
ref184.putEnumerated( id1574, id1575, id1576 );
desc350.putReference( id1573, ref184 );
var id1577 = charIDToTypeID( "Nm " );
desc350.putString( id1577, str ); // layer name here
var id1578 = charIDToTypeID( "Vrsn" );
desc350.putInteger( id1578, 2 );
executeAction( id1572, desc350, DialogModes.NO );
}
But the function works fine with
transform_by_type("bicubicAutomatic");
Thought someone else out to know.
Copy link to clipboard
Copied
I've stabilised it with an if /else:
if (transformtype == "nn") // avoids passing string directly to stringIDToTypeID
{
var idNrst = charIDToTypeID( "Nrst" );
desc5623.putEnumerated( idIntr, idIntp, idNrst );
}
else
{
var idbicubicAutomatic = stringIDToTypeID( "bicubicAutomatic" );
desc5623.putEnumerated( idIntr, idIntp, idbicubicAutomatic );
}