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

Batch Replace Smart Object With Different Image Quality and Sizes

New Here ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

Hi there,

I need help. I have this template that is in 1000x1000pixel and 300 dpi. I'm trying to replace the smart object inside with various JPEG that I have. These JPEG comes in large image sizes but lower than 300dpi. The issues is, when I run the script that I have, some of the pictures become really pixelated. Beforehand, I resized them to fit into the empty place in sizes that I find fit the best (8 cm x 6 cm). Some of them work okey, but then some of them just pretty bad. I'm wondering if you can help me fix the script that I have so I didn't have to resized the images before running the script, and how to make all the image fit automatically to the initial size of the image that I put the first there.

below is the script that I am using and the screenshot of my template:

#target photoshop

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var thePath = myDocument.path;

var theLayer = myDocument.activeLayer;

// psd options;

psdOpts = new PhotoshopSaveOptions();

psdOpts.embedColorProfile = true;

psdOpts.alphaChannels = true;

psdOpts.layers = true;

psdOpts.spotColors = true;

// check if layer is smart object;

if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

else {

// select files;

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.psd;*.jpg;*.jpeg;*.tif", true)}

else {var theFiles = File.openDialog ("please select files", getFiles, true)};

if (theFiles) {

// work through the array;

for (var m = 0; m < theFiles.length; m++) {

// replace smart object;

theLayer = replaceContents (theFiles, theLayer);

var theNewName = theFiles.name.match(/(.*)\.[^\.]+$/)[1];

//Raise color picker for Back cover;

try {

app.activeDocument.activeLayer = app.activeDocument.layers[app.activeDocument.layers.length - 1];

// =======================================================

var idsetd = charIDToTypeID( "setd" );

var desc7 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );

var ref2 = new ActionReference();

var idcontentLayer = stringIDToTypeID( "contentLayer" );

var idOrdn = charIDToTypeID( "Ordn" );

var idTrgt = charIDToTypeID( "Trgt" );

ref2.putEnumerated( idcontentLayer, idOrdn, idTrgt );

desc7.putReference( idnull, ref2 );

var idT = charIDToTypeID( "T " );

var desc8 = new ActionDescriptor();

var idClr = charIDToTypeID( "Clr " );

var idsolidColorLayer = stringIDToTypeID( "solidColorLayer" );

desc7.putObject( idT, idsolidColorLayer, desc8 );

executeAction( idsetd, desc7, DialogModes.ALL );

} catch (e) {};

//save jpg;

myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".jpg")),psdOpts,true);

}

}

}

};

////// get psds, tifs and jpgs from files //////

function getFiles (theFile) {

if (theFile.name.match(/\.(psd|tif|jpeg|jpg)$/i) != null || theFile.constructor.name == "Folder") {

return true

};

};

////// replace contents //////

function replaceContents (newFile, theSO) {

app.activeDocument.activeLayer = theSO;

// =======================================================

var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );

var desc3 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );

desc3.putPath( idnull, new File( newFile ) );

var idPgNm = charIDToTypeID( "PgNm" );

desc3.putInteger( idPgNm, 1 );

executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );

return app.activeDocument.activeLayer

};

Screen Shot 2015-03-16 at 2.33.24 PM.png

TOPICS
Actions and scripting

Views

2.6K

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
Community Expert ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

Do the replacement images all have the same proportions as the Smart Object?

If not how are they to be placed – according to the original SO’s width or height?

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 ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

The replacement images have the same proportions, I only run portraits images to replace portraits, they are just in different size and pixels. I wish to place it according to the original SO's width and height.

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 ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

This would scale the placed SO according to the original SO’s width.

If they all indeed have the same proportions that should suffice.

// 2015, use it at your own risk;

#target "photoshop-70.032"

if (app.documents.length > 0) {

var myDocument = app.activeDocument;

var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];

var thePath = myDocument.path;

var theLayer = myDocument.activeLayer;

// psd options;

psdOpts = new PhotoshopSaveOptions();

psdOpts.embedColorProfile = true;

psdOpts.alphaChannels = true;

psdOpts.layers = true;

psdOpts.spotColors = true;

// check if layer is smart object;

if (theLayer.kind != "LayerKind.SMARTOBJECT") {alert ("selected layer is not a smart object")}

else {

// select files;

if ($.os.search(/windows/i) != -1) {var theFiles = File.openDialog ("please select files", "*.psd;*.jpg;*.jpeg;*.tif", true)}

else {var theFiles = File.openDialog ("please select files", getFiles, true)};

if (theFiles) {

// set to pixels;

var originalRulerUnits = app.preferences.rulerUnits;

app.preferences.rulerUnits = Units.PIXELS;

// get bounds;

var theBounds = theLayer.bounds;

// work through the array;

for (var m = 0; m < theFiles.length; m++) {

// replace smart object;

theLayer = replaceContents (theFiles, theLayer);

var theNewName = theFiles.name.match(/(.*)\.[^\.]+$/)[1];

// scale;

var newBounds = theLayer.bounds;

var theFactor = (Number(theBounds[2])-Number(theBounds[0]))/(Number(newBounds[2])-Number(newBounds[0]))*100;

theLayer.resize(theFactor, theFactor, AnchorPosition.MIDDLECENTER);

//save psd;

myDocument.saveAs((new File(thePath+"/"+theName+"_"+theNewName+".psd")),psdOpts,true);

};

// reset;

originalRulerUnits = app.preferences.rulerUnits;

}

}

};

////// get psds, tifs and jpgs from files //////

function getFiles (theFile) {

if (theFile.name.match(/\.(psd|tif|jpeg|jpg)$/i) != null || theFile.constructor.name == "Folder") {

return true

};

};

////// replace contents //////

function replaceContents (newFile, theSO) {

app.activeDocument.activeLayer = theSO;

// =======================================================

var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );

var desc3 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );

desc3.putPath( idnull, new File( newFile ) );

var idPgNm = charIDToTypeID( "PgNm" );

desc3.putInteger( idPgNm, 1 );

executeAction( idplacedLayerReplaceContents, desc3, DialogModes.NO );

return app.activeDocument.activeLayer

};

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 ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

Thanks!

I got into an error with this script. Screenshot attached below:

Screen Shot 2015-03-16 at 4.39.04 PM.png

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
Enthusiast ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

There is a space between the last number that should not be there *1 00; should be *100;

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 ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

This is perfect! Thank you for all of you for the help. Really appreciate it

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 ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

Sorry, this came up after I successfully scripted 5 images.

Screen Shot 2015-03-16 at 6.05.47 PM.png

How can I fix 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
Community Expert ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

What is theFactor in this case?

Could you please post a screenshot with the Layers Panel visible?

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 ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

What alert do you get when you insert the line

alert ("old bounds\n"+theBounds.join("\n")+"\n\nnew bounds\n"+newBounds.join("\n"));

before

var theFactor = (Number(theBounds[2])-Number(theBounds[0]))/(Number(newBounds[2])-Number(newBounds[0]))*100;

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 ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

this is what happen if I put the alert line in the script:

Screen Shot 2015-03-17 at 9.57.07 AM.png

And this is my layer panel:

Screen Shot 2015-03-17 at 9.57.26 AM.png

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 ,
Mar 17, 2015 Mar 17, 2015

Copy link to clipboard

Copied

Both bounds seem OK.

Does the Script always fail at some particular images?

Replacing a smart object content is a red herring when different sizes and aspect ratios are involved.

Scaling the Smart Object with the replaced content would hardly seem to be more problematic than scaling a straight Layer.

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 ,
Mar 17, 2015 Mar 17, 2015

Copy link to clipboard

Copied

Every Smart Object layer has as associated transform.  That transform the pixels generated for the object.    When you replace the object contents you change the generated pixels if you change the number of pixels the associated transform was not set to transform an image that size.  The transformed image will not be done the way you want but it will be done. This effect the layer size. Which will also not be the image size.   So to get  the correct image size I always transform the object size to 100% wide and 100% high.  Once I do the I can get the images actual size and then transform it to fit are image area and mask off any excess when images with different aspect ratios are selected.

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
New Here ,
Mar 18, 2015 Mar 18, 2015

Copy link to clipboard

Copied

It used to work until it stops with that error and then it doesn't work at all now, but to show the bound alert.

I am sorry for the hassle I caused. Utterly confused here.

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 ,
Mar 19, 2015 Mar 19, 2015

Copy link to clipboard

Copied

Please remove the previous alert and add

alert (theFactor)

before

theLayer.resize(theFactor, theFactor, AnchorPosition.MIDDLECENTER);

What does that yield before the Script errors out?

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 ,
Mar 22, 2015 Mar 22, 2015

Copy link to clipboard

Copied

Hi, I just tried that one. It pops this alert.

Screen Shot 2015-03-23 at 1.07.13 PM.png

I think it needs a coordinate or some sort of the initial images.

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 ,
Mar 23, 2015 Mar 23, 2015

Copy link to clipboard

Copied

LATEST

The alert

alert (theFactor)

should present just the scaling factor, have you not inserted that line?

The bounds of the original SO are evaluated before the for-clause starts so the issue would probably be with the bounds of the replaced SO.

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 ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

I do what you want to do all the time, However I may not always do  it by replacing the smart layer contents.  I may replace the layer or change the smart object layer transform after replacing the contents..   Replacing a smart object content is a red herring when different sizes and aspect ratios are involved.  It does not work without additional work.   You need  the replacement to be sized positioned and masked  to where it should be,    My templates have alpha channels that map image location shape and size.  The Alpha channel are named  "Image 1", "Image 2" .... Image n and image are populated in order layered just above the background layer,  Populated composite retain these  Alpha channels so they can be used to replace image layers.  I only have one script to replace that will current layer populated image.  However all populating script can place any size image to location.

Not good looking lots of script listener code here.  It was also coded back is CS2 timeframe where selection bounds did not work so I needed to hammer out a selections bounds. I was also just starting to hack at scripting. There were bugs added in various version of Photoshop where I needed to add patches to keep the scripts working.  This script will also fail in perpetual CS6 if the users default interpolation method is Adobe default "Bicubic Automatic" for Adobe failed to add support into CS6 scripting.  I filed a bug report. Adobe fixed the Bug in the subscription CS6 version 13.1.2  but not in the perpetual verion 13.0.1.3.  I do not know if it is fixed in the Mac version 13.0.6.

/* ==========================================================

// 2010  John J. McAssey (JJMack)

// ======================================================= */

// This script is supplied as is. It is provided as freeware.

// The author accepts no liability for any problems arising from its use.

// Image files and Template Alpha Channel "Image 1" should have the same orientation matching Aspect

// ratio is even better.  This script will try to transform the placed Images to match the Image 1 Alpha channel as

// best as it can and even try to handle orientation miss matches.

/* Help Category note tag menu can be used to place script in automate menu

<javascriptresource>

<about>$$$/JavaScripts/ReplaceCollageImage/About=JJMack's Replace Collage Image.^r^rCopyright 2010 Mouseprints.^r^rReplace Collage Populated Image</about>

<category>JJMack's Collage Script</category>

</javascriptresource>

*/

// enable double-clicking from Mac Finder or Windows Explorer

#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events

app.bringToFront();

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

//       SET-UP

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

cTID = function(s) { return app.charIDToTypeID(s); };

sTID = function(s) { return app.stringIDToTypeID(s); };

//

var gVersion = 1.0;

// a global variable for the title of the dialog

// this string will also be used for the preferences file I write to disk

// Photoshop Install Directory/Presets/Image Processor/Image Processor.xml for example

var gScriptName = "ReplaceCollageImage";

// remember the dialog modes

var saveDialogMode = app.displayDialogs;

app.displayDialogs = DialogModes.NO;

try {

  // make sure they are running Photoshop CS2

  CheckVersion();

}

// Lot's of things can go wrong, Give a generic alert and see if they want the details

catch(e) {

  if ( confirm("Sorry, something major happened and I can't continue! Would you like to see more info?" ) ) {

  alert(e);

  }

}

// Save the current preferences

var startRulerUnits = app.preferences.rulerUnits;

var startTypeUnits = app.preferences.typeUnits;

var startDisplayDialogs = app.displayDialogs;

// Set Photoshop to use pixels and display no dialogs

app.preferences.rulerUnits = Units.PIXELS;

app.preferences.typeUnits = TypeUnits.PIXELS;

app.displayDialogs = DialogModes.NO;

// Set the script location

var scriptLocation = findScript() + "0";

//=====================Start=====================================================

var doc = activeDocument;

var saveactivelayer = activeDocument.activeLayer

var layers = activeDocument.layers;

activeDocument.activeLayer = layers[layers.length-1]; // Target Bottom Layer

if ( !activeDocument.activeLayer.isBackgroundLayer ) {

  alert("Document does not have the Required Photoshop Background Layer");

  }

else { // Has Background

  var abort = false;

  // ======Load Image 1 Selection===============================

  var idsetd = charIDToTypeID( "setd" );

     var desc2 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref1 = new ActionReference();

        var idChnl = charIDToTypeID( "Chnl" );

         var idfsel = charIDToTypeID( "fsel" );

         ref1.putProperty( idChnl, idfsel );

     desc2.putReference( idnull, ref1 );

     var idT = charIDToTypeID( "T   " );

        var ref2 = new ActionReference();

         var idChnl = charIDToTypeID( "Chnl" );

         ref2.putName( idChnl, "Image 1" );

     desc2.putReference( idT, ref2 );

  try{

  executeAction( idsetd, desc2, DialogModes.NO );

  }catch(e){

  alert("Document does not have the Required Image 1 Alpha Channel");

  var abort = true

  }

  var imageNumber = 1;

  var numberOfImages = getAlphaImageChannels()

  //alert("numberOfImages = " + numberOfImages + " Number of Layers = " + layers.length + " saveactivelayer = " + saveactivelayer  );

  for (var i = layers.length-1; i>=0; i--) { if (layers==saveactivelayer) layernumber = i;};

        imageNumber = (layers.length-1)-layernumber;

  activeDocument.activeLayer = saveactivelayer;

  //alert ("layernumber = " + layernumber + " imageNumber = " + imageNumber);

  if ( imageNumber >= 1 && imageNumber <= numberOfImages && activeDocument.activeLayer.kind  == LayerKind.SMARTOBJECT) { //active layer is within the range of image 1 through Image n

  file = File.openDialog("Select Image" , "Select:*.nef;*.cr2;*.crw;*.dcs;*.raf;*.arw;*.orf;*.dng;*.psd;*.tif;*.tiff;*.jpg;*.jpe;*.jpeg;*.png;*.bmp");

  if ( file != null ) { // image selected

  //alert("file = " + file);

  deletelayermask()

  replaceImage(file)

  // resize smart object layer to just cover canvas area aspect ratio and size

  // Get Smart Object current width and height

  var LB = activeDocument.activeLayer.bounds;

  var LWidth = (LB[2].value) - (LB[0].value);

  var LHeight = (LB[3].value) - (LB[1].value);

  // Get Alpha Channel's width and height Selection Bounds did not work???

  makeLayer(); // Make Temp Work Layer

  loadAlpha("Image " + imageNumber ); // Load Image Alpha Channel

  fillBlack();

  activeDocument.selection.invert(); // Inverse

  // If image size equals canvas size no pixels neill be selected clear will fail

  try{

  activeDocument.selection.clear(); // One clear did not work

  activeDocument.selection.clear(); // Two did the trick

  }catch(e){}

  activeDocument.selection.deselect(); // Deselect

  var SB = activeDocument.activeLayer.bounds; // Get the bounds of the work layer

  var SWidth = (SB[2].value) - (SB[0].value); // Area width

  var SHeight = (SB[3].value) - (SB[1].value); // Area height

  activeDocument.activeLayer.remove(); // Remove Work layer

  var userResampleMethod = app.preferences.interpolation; // Save interpolation settings

  app.preferences.interpolation = ResampleMethod.BICUBIC; // resample interpolation bicubic

  if (LWidth/LHeight<SWidth/SHeight) { // Smart Object layer Aspect Ratio less the Canvas area Aspect Ratio

  var percentageChange = ((SWidth/LWidth)*100);  // Resize to canvas area width

  activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);

  }

  else {

  var percentageChange = ((SHeight/LHeight)*100); // resize to canvas area height

  activeDocument.activeLayer.resize(percentageChange,percentageChange,AnchorPosition.MIDDLECENTER);

  }

  app.preferences.interpolation = userResampleMethod; // Reset interpolation setting

  // Load Alpha Channel as a selection and align image to it

  loadAlpha("Image " + imageNumber);

  //align('AdTp');

  //align('AdLf');

  align('AdCV');

  align('AdCH');

  // Add Layer mask using Alpha channel Image1

  // linkedlayerMask(); // Add inked Layer Mask

  layerMask(); // Add Layer Mask

  targetRGB()

  // Isolate Image name

  var Name =  decodeURI(file).replace(/\.[^\.]+$/, ''); // strip the extension off

  var imagePath = "";

  while (Name.indexOf("/") != -1 ) { // Strip Path

  imagePath= imagePath + Name.substr(0, Name.indexOf("/") + 1);

  Name = Name.substr(Name.indexOf("/") + 1 ,);

  }

  if (Name.indexOf("#") != -1 ) { // Strip any prefix sequence number off

  prefix = Name.substr(0,Name.indexOf("#") );

  Name = Name.substr(Name.indexOf("#") + 1 ,);

  }

  app.activeDocument.activeLayer.name = Name

  } // end not null

  } //end is an image layer

  else { alert("Target a Smart Object Image layer to replace/"); }

} //end has Background

// Return the app preferences

app.preferences.rulerUnits = startRulerUnits;

app.preferences.typeUnits = startTypeUnits;

app.displayDialogs = saveDialogMode;

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

// The end //

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

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

// Helper Functions //

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

function placeImage(file) {

  // =======avoid bug in cs2 and maybe CS4 ==================================

  var idslct = charIDToTypeID( "slct" );

     var desc5 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref3 = new ActionReference();

         var idChnl = charIDToTypeID( "Chnl" );

         var idChnl = charIDToTypeID( "Chnl" );

         var idRGB = charIDToTypeID( "RGB " );

         ref3.putEnumerated( idChnl, idChnl, idRGB );

     desc5.putReference( idnull, ref3 );

     var idMkVs = charIDToTypeID( "MkVs" );

     desc5.putBoolean( idMkVs, false );

  executeAction( idslct, desc5, DialogModes.NO );

  // Place in the file

  var idPlc = charIDToTypeID( "Plc " );

     var desc5 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

     desc5.putPath( idnull, new File( file ) );

     var idFTcs = charIDToTypeID( "FTcs" );

     var idQCSt = charIDToTypeID( "QCSt" );

     var idQcsa = charIDToTypeID( "Qcsa" );

     desc5.putEnumerated( idFTcs, idQCSt, idQcsa );

     var idOfst = charIDToTypeID( "Ofst" );

         var desc6 = new ActionDescriptor();

         var idHrzn = charIDToTypeID( "Hrzn" );

         var idPxl = charIDToTypeID( "#Pxl" );

         desc6.putUnitDouble( idHrzn, idPxl, 0.000000 );

         var idVrtc = charIDToTypeID( "Vrtc" );

         var idPxl = charIDToTypeID( "#Pxl" );

         desc6.putUnitDouble( idVrtc, idPxl, 0.000000 );

     var idOfst = charIDToTypeID( "Ofst" );

     desc5.putObject( idOfst, idOfst, desc6 );

  executeAction( idPlc, desc5, DialogModes.NO );

  // because can't get the scale of a smart object, reset to 100%

  activeDocument.activeLayer.resize(100 ,100,AnchorPosition.MIDDLECENTER);

  return app.activeDocument.activeLayer;

}

function targetRGB() {

  // =======avoid bug in cs2 and maybe CS4 ==================================

  var idslct = charIDToTypeID( "slct" );

     var desc5 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref3 = new ActionReference();

         var idChnl = charIDToTypeID( "Chnl" );

         var idChnl = charIDToTypeID( "Chnl" );

         var idRGB = charIDToTypeID( "RGB " );

         ref3.putEnumerated( idChnl, idChnl, idRGB );

     desc5.putReference( idnull, ref3 );

     var idMkVs = charIDToTypeID( "MkVs" );

     desc5.putBoolean( idMkVs, false );

  executeAction( idslct, desc5, DialogModes.NO );

}

function replaceImage(file) {

  // =======avoid bug in cs2 and maybe CS4 ==================================

  var idslct = charIDToTypeID( "slct" );

     var desc5 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref3 = new ActionReference();

         var idChnl = charIDToTypeID( "Chnl" );

         var idChnl = charIDToTypeID( "Chnl" );

         var idRGB = charIDToTypeID( "RGB " );

         ref3.putEnumerated( idChnl, idChnl, idRGB );

     desc5.putReference( idnull, ref3 );

     var idMkVs = charIDToTypeID( "MkVs" );

     desc5.putBoolean( idMkVs, false );

  executeAction( idslct, desc5, DialogModes.NO );

  // ===============Replace Contents========================================

  var idplacedLayerReplaceContents = stringIDToTypeID( "placedLayerReplaceContents" );

     var desc18 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

     desc18.putPath( idnull, new File( file ) );

  executeAction( idplacedLayerReplaceContents, desc18, DialogModes.NO );

  // because can't get the scale of a smart object, reset to 100%

  activeDocument.activeLayer.resize(100 ,100,AnchorPosition.MIDDLECENTER);

}

function deletelayermask() {

  var idDlt = charIDToTypeID( "Dlt " );

     var desc17 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref17 = new ActionReference();

         var idChnl = charIDToTypeID( "Chnl" );

         var idChnl = charIDToTypeID( "Chnl" );

         var idMsk = charIDToTypeID( "Msk " );

         ref17.putEnumerated( idChnl, idChnl, idMsk );

     desc17.putReference( idnull, ref17 );

  try{

  executeAction( idDlt, desc17, DialogModes.NO );

  }catch(e){}

}

function makeLayer(){

  var idMk = charIDToTypeID( "Mk  " );

     var desc4 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref3 = new ActionReference();

         var idLyr = charIDToTypeID( "Lyr " );

         ref3.putClass( idLyr );

     desc4.putReference( idnull, ref3 );

  executeAction( idMk, desc4, DialogModes.NO );

}

function layerBackward(){

  var idslct = charIDToTypeID( "slct" );

     var desc9 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

        var ref6 = new ActionReference();

         var idLyr = charIDToTypeID( "Lyr " );

         var idOrdn = charIDToTypeID( "Ordn" );

         var idBckw = charIDToTypeID( "Bckw" );

        ref6.putEnumerated( idLyr, idOrdn, idBckw );

     desc9.putReference( idnull, ref6 );

     var idMkVs = charIDToTypeID( "MkVs" );

     desc9.putBoolean( idMkVs, false );

  executeAction( idslct, desc9, DialogModes.NO );

}

function layerForward(){

  var idslct = charIDToTypeID( "slct" );

     var desc26 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref19 = new ActionReference();

        var idLyr = charIDToTypeID( "Lyr " );

        var idOrdn = charIDToTypeID( "Ordn" );

         var idFrwr = charIDToTypeID( "Frwr" );

         ref19.putEnumerated( idLyr, idOrdn, idFrwr );

    desc26.putReference( idnull, ref19 );

     var idMkVs = charIDToTypeID( "MkVs" );

     desc26.putBoolean( idMkVs, false );

  executeAction( idslct, desc26, DialogModes.NO );

}

function fillBlack(){

// ============Fill with Black==========================================

  var idFl = charIDToTypeID( "Fl  " );

    var desc11 = new ActionDescriptor();

     var idUsng = charIDToTypeID( "Usng" );

     var idFlCn = charIDToTypeID( "FlCn" );

   var idBlck = charIDToTypeID( "Blck" );

    desc11.putEnumerated( idUsng, idFlCn, idBlck );

     var idOpct = charIDToTypeID( "Opct" );

     var idPrc = charIDToTypeID( "#Prc" );

     desc11.putUnitDouble( idOpct, idPrc, 100.000000 );

     var idMd = charIDToTypeID( "Md  " );

     var idBlnM = charIDToTypeID( "BlnM" );

     var idNrml = charIDToTypeID( "Nrml" );

     desc11.putEnumerated( idMd, idBlnM, idNrml );

  executeAction( idFl, desc11, DialogModes.NO );

}

function fillColor(){

  var idFl = charIDToTypeID( "Fl  " );

   var desc17 = new ActionDescriptor();

    var idUsng = charIDToTypeID( "Usng" );

    var idFlCn = charIDToTypeID( "FlCn" );

     var idClr = charIDToTypeID( "Clr " );

     desc17.putEnumerated( idUsng, idFlCn, idClr );

    var idClr = charIDToTypeID( "Clr " );

        var desc18 = new ActionDescriptor();

        var idH = charIDToTypeID( "H   " );

         var idAng = charIDToTypeID( "#Ang" );

         desc18.putUnitDouble( idH, idAng, 172.232666 );

         var idStrt = charIDToTypeID( "Strt" );

         desc18.putDouble( idStrt, 35.686275 );

         var idBrgh = charIDToTypeID( "Brgh" );

         desc18.putDouble( idBrgh, 93.725490 );

     var idHSBC = charIDToTypeID( "HSBC" );

    desc17.putObject( idClr, idHSBC, desc18 );

     var idOpct = charIDToTypeID( "Opct" );

     var idPrc = charIDToTypeID( "#Prc" );

     desc17.putUnitDouble( idOpct, idPrc, 100.000000 );

    var idMd = charIDToTypeID( "Md  " );

     var idBlnM = charIDToTypeID( "BlnM" );

     var idNrml = charIDToTypeID( "Nrml" );

     desc17.putEnumerated( idMd, idBlnM, idNrml );

  executeAction( idFl, desc17, DialogModes.NO );

}

function deleteSelection(){

  var idDlt = charIDToTypeID( "Dlt " );

  executeAction( idDlt, undefined, DialogModes.NO );

}

function deleteLayer(){

  var idDlt = charIDToTypeID( "Dlt " );

   var desc25 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

       var ref18 = new ActionReference();

       var idLyr = charIDToTypeID( "Lyr " );

       var idOrdn = charIDToTypeID( "Ordn" );

       var idTrgt = charIDToTypeID( "Trgt" );

        ref18.putEnumerated( idLyr, idOrdn, idTrgt );

    desc25.putReference( idnull, ref18 );

  executeAction( idDlt, desc25, DialogModes.NO );

}

function addStyle(Style){

  var idASty = charIDToTypeID( "ASty" );

     var desc20 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref3 = new ActionReference();

         var idStyl = charIDToTypeID( "Styl" );

         ref3.putName( idStyl, Style );

     desc20.putReference( idnull, ref3 );

     var idT = charIDToTypeID( "T   " );

         var ref4 = new ActionReference();

         var idLyr = charIDToTypeID( "Lyr " );

         var idOrdn = charIDToTypeID( "Ordn" );

         var idTrgt = charIDToTypeID( "Trgt" );

         ref4.putEnumerated( idLyr, idOrdn, idTrgt );

     desc20.putReference( idT, ref4 );

  try{

  executeAction( idASty, desc20, DialogModes.NO);

  }catch(e){}

}

function SaveAsJPEG(saveFile, jpegQuality){

  var doc = activeDocument;

  if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) doc.bitsPerChannel = BitsPerChannelType.EIGHT;

  jpgSaveOptions = new JPEGSaveOptions();

  jpgSaveOptions.embedColorProfile = true;

  jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;

  jpgSaveOptions.matte = MatteType.NONE;

  jpgSaveOptions.quality = jpegQuality;

  activeDocument.saveAs(File(saveFile+".jpg"), jpgSaveOptions, true,Extension.LOWERCASE);

}

function SaveAsPSD( inFileName, inEmbedICC ) {

  var psdSaveOptions = new PhotoshopSaveOptions();

  psdSaveOptions.embedColorProfile = inEmbedICC;

  app.activeDocument.saveAs( File( inFileName + ".psd" ), psdSaveOptions );

}

function SaveAsPDF( saveFile ) {

  var idsave = charIDToTypeID( "save" );

     var desc2 = new ActionDescriptor();

     var idAs = charIDToTypeID( "As  " );

         var desc3 = new ActionDescriptor();

         var idpdfPresetFilename = stringIDToTypeID( "pdfPresetFilename" );

         desc3.putString( idpdfPresetFilename, "High Quality Print" );

         var idpdfCompatibilityLevel = stringIDToTypeID( "pdfCompatibilityLevel" );

         var idpdfCompatibilityLevel = stringIDToTypeID( "pdfCompatibilityLevel" );

         var idpdfoneeight = stringIDToTypeID( "pdf18" );

         desc3.putEnumerated( idpdfCompatibilityLevel, idpdfCompatibilityLevel, idpdfoneeight );

         var idpdfCompressionType = stringIDToTypeID( "pdfCompressionType" );

         desc3.putInteger( idpdfCompressionType, 7 );

     var idPhtP = charIDToTypeID( "PhtP" );

     desc2.putObject( idAs, idPhtP, desc3 );

     var idIn = charIDToTypeID( "In  " );

     desc2.putPath( idIn, new File( saveFile + ".pdf" ) );

  executeAction( idsave, desc2, DialogModes.NO );

}

function align(method) {

  var desc = new ActionDescriptor();

  var ref = new ActionReference();

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

  desc.putReference( charIDToTypeID( "null" ), ref );

  desc.putEnumerated( charIDToTypeID( "Usng" ), charIDToTypeID( "ADSt" ), charIDToTypeID( method ) );

  try{

  executeAction( charIDToTypeID( "Algn" ), desc, DialogModes.NO );

  }catch(e){}

}

function getAlphaImageChannels() {

  for (var n = 1; n < 999; n++) {

  // ======Load Image n Selection===============================

  var idsetd = charIDToTypeID( "setd" );

     var desc2 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref1 = new ActionReference();

         var idChnl = charIDToTypeID( "Chnl" );

         var idfsel = charIDToTypeID( "fsel" );

         ref1.putProperty( idChnl, idfsel );

     desc2.putReference( idnull, ref1 );

     var idT = charIDToTypeID( "T   " );

         var ref2 = new ActionReference();

         var idChnl = charIDToTypeID( "Chnl" );

         ref2.putName( idChnl, "Image " + n );

     desc2.putReference( idT, ref2 );

  try{

  executeAction( idsetd, desc2, DialogModes.NO );

  }catch(e){

  activeDocument.selection.deselect(); // Deselect

  //alert ("n = " + n);

  return n - 1;

  }

  }

}

// ======Load Alpha Channel Selection===============================

function loadAlpha(channel) {

  var idsetd = charIDToTypeID( "setd" );

     var desc2 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref1 = new ActionReference();

         var idChnl = charIDToTypeID( "Chnl" );

         var idfsel = charIDToTypeID( "fsel" );

         ref1.putProperty( idChnl, idfsel );

     desc2.putReference( idnull, ref1 );

     var idT = charIDToTypeID( "T   " );

         var ref2 = new ActionReference();

         var idChnl = charIDToTypeID( "Chnl" );

         ref2.putName( idChnl, channel );

     desc2.putReference( idT, ref2 );

  executeAction( idsetd, desc2, DialogModes.NO );

}

// =======linked layer Mask========================================

function linkedlayerMask() {

  var idMk = charIDToTypeID( "Mk  " );

     var desc3 = new ActionDescriptor();

     var idNw = charIDToTypeID( "Nw  " );

     var idChnl = charIDToTypeID( "Chnl" );

     desc3.putClass( idNw, idChnl );

     var idAt = charIDToTypeID( "At  " );

         var ref3 = new ActionReference();

         var idChnl = charIDToTypeID( "Chnl" );

         var idChnl = charIDToTypeID( "Chnl" );

         var idMsk = charIDToTypeID( "Msk " );

         ref3.putEnumerated( idChnl, idChnl, idMsk );

     desc3.putReference( idAt, ref3 );

     var idUsng = charIDToTypeID( "Usng" );

     var idUsrM = charIDToTypeID( "UsrM" );

     var idRvlS = charIDToTypeID( "RvlS" );

     desc3.putEnumerated( idUsng, idUsrM, idRvlS );

  executeAction( idMk, desc3, DialogModes.NO );

}

// =======Un linked layer Mask========================================

function layerMask() {

  var idMk = charIDToTypeID( "Mk  " );

     var desc3 = new ActionDescriptor();

     var idNw = charIDToTypeID( "Nw  " );

     var idChnl = charIDToTypeID( "Chnl" );

     desc3.putClass( idNw, idChnl );

     var idAt = charIDToTypeID( "At  " );

         var ref3 = new ActionReference();

         var idChnl = charIDToTypeID( "Chnl" );

         var idChnl = charIDToTypeID( "Chnl" );

         var idMsk = charIDToTypeID( "Msk " );

         ref3.putEnumerated( idChnl, idChnl, idMsk );

     desc3.putReference( idAt, ref3 );

     var idUsng = charIDToTypeID( "Usng" );

     var idUsrM = charIDToTypeID( "UsrM" );

     var idRvlS = charIDToTypeID( "RvlS" );

     desc3.putEnumerated( idUsng, idUsrM, idRvlS );

  executeAction( idMk, desc3, DialogModes.NO );

  // =======================================================

  var idsetd = charIDToTypeID( "setd" );

     var desc2 = new ActionDescriptor();

     var idnull = charIDToTypeID( "null" );

         var ref1 = new ActionReference();

         var idLyr = charIDToTypeID( "Lyr " );

         var idOrdn = charIDToTypeID( "Ordn" );

         var idTrgt = charIDToTypeID( "Trgt" );

         ref1.putEnumerated( idLyr, idOrdn, idTrgt );

     desc2.putReference( idnull, ref1 );

     var idT = charIDToTypeID( "T   " );

         var desc3 = new ActionDescriptor();

         var idUsrs = charIDToTypeID( "Usrs" );

         desc3.putBoolean( idUsrs, false );

     var idLyr = charIDToTypeID( "Lyr " );

     desc2.putObject( idT, idLyr, desc3 );

  executeAction( idsetd, desc2, DialogModes.NO );

}

function help() {

  try{

  var URL = new File(Folder.temp + "/PhotoCollageToolkit.html");

  URL.open("w");

  URL.writeln('<html><HEAD><meta HTTP-EQUIV="REFRESH" content="0; url=http://www.mouseprints.net/old/dpr/PhotoCollageToolkit.html"></HEAD></HTML>');

  URL.close();

  URL.execute();

  }catch(e){

  alert("Error, Can Not Open.");

  };

}

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

// Function: initExportInfo

// Usage: create our default parameters

// Input: a new Object

// Return: a new object with params set to default

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

function initExportInfo(exportInfo) {

    exportInfo.destination = new String("");

    exportInfo.fileNamePrefix = new String("untitled_");

    exportInfo.visibleOnly = false;

//    exportInfo.fileType = psdIndex;

    exportInfo.icc = true;

    exportInfo.jpegQuality = 8;

    exportInfo.psdMaxComp = true;

    exportInfo.tiffCompression = TIFFEncoding.NONE;

    exportInfo.tiffJpegQuality = 8;

    exportInfo.pdfEncoding = PDFEncoding.JPEG;

    exportInfo.pdfJpegQuality = 8;

    exportInfo.targaDepth = TargaBitsPerPixels.TWENTYFOUR;

    exportInfo.bmpDepth = BMPDepthType.TWENTYFOUR;

    try {

         exportInfo.destination = Folder(app.activeDocument.fullName.parent).fsName; // destination folder

        var tmp = app.activeDocument.fullName.name;

        exportInfo.fileNamePrefix = decodeURI(tmp.substring(0, tmp.indexOf("."))); // filename body part

    } catch(someError) {

        exportInfo.destination = new String("");

//        exportInfo.fileNamePrefix = app.activeDocument.name; // filename body part

    }

}

// Find the location where this script resides

function findScript() {

  var where = "";

  try {

  FORCEERROR = FORCERRROR;

  }

  catch(err) {

  // alert(err.fileName);

  // alert(File(err.fileName).exists);

  where = File(err.fileName);

  }

  return where;

}

// Function for returning current date and time

    function getDateTime() {

        var date = new Date();

        var dateTime = "";

        if ((date.getMonth() + 1) < 10) {

            dateTime += "0" + (date.getMonth() + 1) + "/";

        } else {

            dateTime += (date.getMonth() + 1) + "/";

        }

        if (date.getDate() < 10) {

            dateTime += "0" + date.getDate() + "/";

        } else {

            dateTime += date.getDate() + "/";

        }

        dateTime += date.getFullYear() + ", ";

        if (date.getHours() < 10) {

            dateTime += "0" + date.getHours() + ":";

        } else {

            dateTime += date.getHours() + ":";

        }

        if (date.getMinutes() < 10) {

            dateTime += "0" + date.getMinutes() + ":";

        } else {

            dateTime += date.getMinutes() + ":";

        }

        if (date.getSeconds() < 10) {

            dateTime += "0" + date.getSeconds();

        } else {

            dateTime += date.getSeconds();

        }

        return dateTime;

    }

// resetPrefs function for resetting the preferences

  function resetPrefs() {

  preferences.rulerUnits = startRulerUnits;

  preferences.typeUnits = startTypeUnits;

  displayDialogs = startDisplayDialogs;

  }

// CheckVersion

function CheckVersion() {

  var numberArray = version.split(".");

  if ( numberArray[0] < 9 ) {

  alert( "You must use Photoshop CS2 or later to run this script!" );

  throw( "You must use Photoshop CS2 or later to run this script!" );

  }

}

// load my params from the xml file on disk if it exists

// gParams["myoptionname"] = myoptionvalue

// I wrote a very simple xml parser, I'm sure it needs work

function LoadParamsFromDisk ( loadFile, params ) {

  // var params = new Array();

  if ( loadFile.exists ) {

  loadFile.open( "r" );

  var projectSpace = ReadHeader( loadFile );

  if ( projectSpace == GetScriptNameForXML() ) {

  while ( ! loadFile.eof ) {

  var starter = ReadHeader( loadFile );

  var data = ReadData( loadFile );

  var ender = ReadHeader( loadFile );

  if ( ( "/" + starter ) == ender ) {

  params[starter] = data;

  }

  // force boolean values to boolean types

  if ( data == "true" || data == "false" ) {

  params[starter] = data == "true";

  }

  }

  }

  loadFile.close();

  if ( params["version"] != gVersion ) {

  // do something here to fix version conflicts

  // this should do it

  params["version"] = gVersion;

  }

  }

  return params;

}

// save out my params, this is much easier

function SaveParamsToDisk ( saveFile, params ) {

  saveFile.encoding = "UTF8";

  saveFile.open( "w", "TEXT", "????" );

  // unicode signature, this is UTF16 but will convert to UTF8 "EF BB BF"

  saveFile.write("\uFEFF");

  var scriptNameForXML = GetScriptNameForXML();

  saveFile.writeln( "<" + scriptNameForXML + ">" );

  for ( var p in params ) {

  saveFile.writeln( "\t<" + p + ">" + params

+ "</" + p + ">" );

  }

  saveFile.writeln( "</" + scriptNameForXML + ">" );

  saveFile.close();

}

// you can't save certain characters in xml, strip them here

// this list is not complete

function GetScriptNameForXML () {

  var scriptNameForXML = new String( gScriptName );

  var charsToStrip = Array( " ", "'", "." );

  for (var a = 0; a < charsToStrip.length; a++ )  {

  var nameArray = scriptNameForXML.split( charsToStrip );

  scriptNameForXML = "";

  for ( var b = 0; b < nameArray.length; b++ ) {

  scriptNameForXML += nameArray;

  }

  }

  return scriptNameForXML;

}

// figure out what I call my params file

function GetDefaultParamsFile() {

  //var paramsFolder = new Folder( path + "/Presets/" + gScriptName );

  //var paramsFolder = new Folder( Folder.temp + "/JJMack's Scripts/" + gScriptName );

  var paramsFolder = new Folder( "~/Application Data/JJMack's Scripts/" + gScriptName );

  //alert("paramsFolder = " + paramsFolder );

  paramsFolder.create();

  return ( new File( paramsFolder + "/" + gScriptName + ".xml" ) );

}

// a very crude xml parser, this reads the "Tag" of the <Tag>Data</Tag>

function ReadHeader( inFile ) {

  var returnValue = "";

  if ( ! inFile.eof ) {

  var c = "";

  while ( c != "<" && ! inFile.eof ) {

  c = inFile.read( 1 );

  }

  while ( c != ">" && ! inFile.eof ) {

  c = inFile.read( 1 );

  if ( c != ">" ) {

  returnValue += c;

  }

  }

  } else {

  returnValue = "end of file";

  }

  return returnValue;

}

// very crude xml parser, this reads the "Data" of the <Tag>Data</Tag>

function ReadData( inFile ) {

  var returnValue = "";

  if ( ! inFile.eof ) {

  var c = "";

  while ( c != "<" && ! inFile.eof ) {

  c = inFile.read( 1 );

  if ( c != "<" ) {

  returnValue += c;

  }

  }

  inFile.seek( -1, 1 );

  }

  return returnValue;

}

// Actions converted with X's ActionFileToJavascript

//==================== Set View for Place ==============

function SetViewforPlace() {

  // Menu View>Fit On Screen

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('FtOn'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, DialogModes.NO);

  // Menu View>Zoom out

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('ZmOt'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, DialogModes.NO);

  // Menu View>screen Mode Full Screen With Menubar

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), sTID("screenModeFullScreenWithMenubar"));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, DialogModes.NO);

};

//==================== Interactive Place ==============

function InteractivePlace() {

  // Menu File>Place

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('Plce'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, DialogModes.NO);

};

//==================== Interactive Transform ==============

function InteractiveTransform() {

  // Menu Edit>Free transform

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('FrTr'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, DialogModes.NO);

};

//==================== Set View Fit on Screen ==============

function SetViewFitonScreen() {

  // Menu View>screen Mode Standard

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), sTID("screenModeStandard"));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, DialogModes.NO);

  // Menu View>Fit on screen

    var desc1 = new ActionDescriptor();

    var ref1 = new ActionReference();

    ref1.putEnumerated(cTID('Mn  '), cTID('MnIt'), cTID('FtOn'));

    desc1.putReference(cTID('null'), ref1);

    executeAction(cTID('slct'), desc1, DialogModes.NO);

};

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
New Here ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

Thank you for the script. If so, should I rasterize the image first on the file? If so, can I still maintain the layer mask so it does not go out of the border that I made?

I tried your script and this error message pops out:

Screen Shot 2015-03-17 at 10.06.54 AM.png

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 ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

Something must have been messed up during paste into this jive site that is not what line 164 is... The script is one in mt Photo Collage toolkit.

Photo Collage Toolkit

Photoshop scripting is powerful and I believe this package demonstrates this A video showing a 5 image collage PSD template  being populates with images:

The package includes four simple rules to follow when making Photo Collage Template PSD files so they will be compatible with my Photoshop scripts.

  1. Size the photo collage templates for the print size you want - width, height and print DPI resolution.
  2. Photo collage templates must have a Photoshop background layer. The contents of this layer can be anything.
  3. Photo collage templates must have alpha channels named "Image 1", "Image 2", ... "Image n".
  4. Photo collage templates layers above the background layers must provide transparent areas to let the images that will be placed below them show through.

There are twelve scripts in this package they provide the following functions:

  1. TestCollageTemplate.jsx - Used to test a Photo Collage Template while you are making it with Photoshop.
  2. CollageTemplateBuilder.jsx - Can build Templates compatible with this toolkit's scripts.
  3. LayerToAlphaChan.jsx - Used to convert a Prototype Image Layer stack into a template document.
  4. InteractivePopulateCollage.jsx - Used to interactively populate Any Photo Collage template. Offers most user control inserting pictures and text.
  5. ReplaceCollageImage.jsx - use to replace a populated collage image Smart Object layer with an other image correctly resized and positioned.
  6. ChangeTextSize.jsx - This script can be used to change Image stamps text size when the size used by the populating did not work well.
  7. PopulateCollageTemplate.jsx - Used to Automatically populate a Photo Collage template and leave the populated copy open in Photoshop.
  8. BatchOneImageCollage.jsx - Used to Automatically Batch Populate Collage templates that only have one image inserted. The Collage or Image may be stamped with text.
  9. BatchMultiImageCollage.jsx - Used to Automatically Batch Populate Any Photo Collage template with images in a source image folder. Easier to use than the interactive script. Saved collages can be tweaked.
  10. BatchPicturePackage.jsx - Used to Automatically Batch Populate Any Photo Collage template with an image in a source image folder
  11. PasteImageRoll.jsx - Paste Images into a document to be print on roll paper.
  12. PCTpreferences.jsx - Edit This File to Customize Collage Populating scripts default setting and add your own Layer styles.

Documentation and Examples

You can see line 164 here

Capture.jpg

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
New Here ,
Mar 16, 2015 Mar 16, 2015

Copy link to clipboard

Copied

I downloaded the script. I have no experience before with alpha layer, which the script are asking me to make. I make an alpha mask but the script doesn't seems to recognize it.

Could you kindly help me through the steps prior the scripting process?

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 ,
Mar 17, 2015 Mar 17, 2015

Copy link to clipboard

Copied

frogeyed wrote:

I have no experience before with alpha layer

Its alpha channel and you do have experience you just don't realize you do.  An alpha channel, a selection and a layer mask are all the same thing a selection.   Alpha channels and layer mask are nothing more than recorded selections.  If you make a selection you can record(save) it using menu select>Save selection to save it as a alpha channel or you can click on the add layer mask and sve(record) the selection as a layer mask.

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
New Here ,
Mar 18, 2015 Mar 18, 2015

Copy link to clipboard

Copied

hmm, okey then. I already have my layer mask. How can I turn that into alpha 1 layer?

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 ,
Mar 18, 2015 Mar 18, 2015

Copy link to clipboard

Copied

Control click on a layer with a layer mask Content icon in the layers palette that will select the layers visibility as a selection.  It load the layer mask as a selection. You can then use menu Select>Save Selection>Alpha channel name.

My scripts require the Image Mapping Alpha channels be name "Image 1". "Image 2", ... "Image n".   Photoshop only supports up to 53 Alpha channels My collage templates for my scripts are limited to 53 Images.

Photoshop supports up to 8000 layers you can layout 8000 image layers and all have layer mask.  You just can not use alpha channels to create the selection for the layer mask.  My PasteImageRoll could create a document like that.   I have no idea how long the script would take to create an 8000 layer document or if your machine may run out or resources first. The image layers created by that script are resized image raster layers not smart object layers like my collage script create. So the layers have much less overhead then smart Object layers the will be small compared  to object layers.

My collage templates have no image layers therefore they have no image layer mask.   Populate Image smart object layer are mask using the requires Image mapping alpha channels. The alpha channels bounds are used to calculate the smart layer transform percentage and also used for positioning the placed transformed image layer.

My collage templates only require a background  layer to place image over.

Four simple rules to follow when making Photo Collage Template PSD files so they will be compatible with my Photoshop scripts.

  1. Size the photo collage templates for the print size you want - width, height and print DPI resolution.
  2. Photo collage templates must have a Photoshop background layer. The contents of this layer can be anything.
  3. Photo collage templates must have alpha channels named "Image 1", "Image 2", ... "Image n".
  4. Photo collage templates layers above the background layers must provide transparent areas to let the images that will be placed below them show through.
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