Script to rotate portrait photos 90 to allow resize thenback

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Philip

Script to rotate portrait photos 90 to allow resize thenback

Post by Philip »

Hello, first post here.

I use Photoshop CS2 and Adobe Camera Raw to batch process photos from my Nikon D70s.

RotatePortraits2A.js is intended to detect portrait photos in a resizing action and to rotate them 90 degrees so any resizing in the action works on the long side instead of the short side.

RotatePortraits2B.js rotates back any photos, at the end of the action, that have been rotated from portrait to landscape by RotatePortraits2A.js by looking for extra layer "Temp"

I am not a programmer. The two scripts RotatePortraits2A.js and RotatePortraits2B.js below have been cobbled together from other scripts I have found.

The problem: they don't always work. Sometimes they work fine, other times they don't and I can't work out the reason.

Any insights very much appreciated.

Philip.

Scripts follow:

//==========RotatePortraits2A.js STARTS HERE=======


// REV.1, 15.07.2005, Philip Coombes. Please feel free to use this script.


// Notes:

// 1. Author is not liable for any problems caused to users by this script.

// 2. This Javascript rotates the open image 90 degrees CCW to landscape ONLY
// when it finds that the height of the image is greater the the width.
// When it does, it adds an extra layer called "Temp" which acts as a label
// which can be seen by RotatePortraits2B.js which will rotate image back
// later in the action.

// 3. This script is designed for batch processing images using an action
// that incorporates resizing. Rotating portrait images avoids incorrect
// sizing.

// 4. It works OK for Photoshop CS2. For CS, if it doesn't run as is, try
// removing the "app." from app.activedocument in both places it is used.

// 5. Whenever an image is rotated a "Rotate Canvas" step will appear in the
// History pallete.

// 6. To use in an action: While recording the action EITHER go File/Script/
// choose RotatePortraits2A.js from the list and click on Run Script
// OR go File/Script/"browse" to it/select it/click on Load.

// 7. To make the script appear in the list when you go File/Scripts put the
// script in C:Program Files/Adobe/PhotoshopCS2/Presets/Scripts and then
// restart Photoshop.

// 8. If this script is not obtained as a file then copy and paste into a
// simple text editor like Notepad (don't use Word) and save the file as
// RotatPortraits1.js. The js suffix identifies it as javascript. You can
// edit the script in Notepad and resave it.




// ++++++++++ The actual script starts here ++++++++++


var this_image=app.activeDocument;


//If height > width then the image must be in portrait mode so rotate it 90 dgrees CCW

if (this_image.height > this_image.width)

{

app.activeDocument.rotateCanvas(-90);

var Temp_Layer = this_image.artLayers.add();

Temp_Layer.name = "Temp";

//Temp_Layer.visiblity = false

this_image.activeLayer = this_image.layers[1];

}

//app.activeDocument.activeLayer.name = docName
//this_image.activeLayer.remove() works!
//app.activeDocument.layers[1].move(app.activeDocument.layers[0], ElementPlacement.PLACEAFTER);
//Fuzzy_Lyr.moveAfter(Filename_Lyr);
//document.layers[1].visibility='hide'
//docRef.info.author = "Mr. Adobe programmer"
//document.all[layerName].style.visibility = "hidden";

// ++++++++++ The actual script stops here ++++++++++



//========RotatePortraits2A.js ENDS HERE=========



Second script here:


//==========RotatePortraits2B.js STARTS HERE=======


// REV.1, 15.07.2005, Philip Coombes. Please feel free to use this script.


// Notes:

// 1. Author is not liable for any problems caused to users by this script.

// 2. This Javascript rotates the open image back 90 degrees CW to put it
// back into portrait orientation. It looks for the image having more
// than one layer as a result of use of script RotatePortraits2A.js

// 3. This script is designed for batch processing images using an action
// that incorporates resizing. Rotating portrait images avoids incorrect
// sizing.

// 4. It works OK for Photoshop CS2. For CS, if it doesn't run as is, try
// removing the "app." from app.activedocument in both places it is used.

// 5. Whenever an image is rotated a"Rotate Canvas" step will appear in the
// History pallete.

// 6. To use in an action: While recording the action EITHER go File/Script/
// choose RotatePortraits2B.js from the list and click on Run Script
// OR go File/Script/"browse" to it/select it/click on Load.

// 7. To make the script appear in the list when you go File/Scripts put the
// script in C:Program Files/Adobe/PhotoshopCS2/Presets/Scripts and then
// restart Photoshop.

// 8. If this script is not obtained as a file then copy and paste into a
// simple text editor like Notepad (don't use Word) and save the file as
// RotatPortraits1.js. The js suffix identifies it as javascript. You can
// edit the script in Notepad and resave it.




// ++++++++++ The actual script starts here ++++++++++


var this_image=app.activeDocument;

if (this_image.layers.length > 1)

{

app.activeDocument.rotateCanvas(90);

this_image.activeLayer = this_image.layers["Temp"];

this_image.activeLayer.remove()

}

//Following are scripts lines I might be able to use elsewghere
//this_image.activeLayer = this_image.layers[this_image.layers.length - 2]; works
//this_image.activeLayer = this_image.layers[0]; works
//var myLayer = app.document.layers["Layer1"];
//myLayer.visibility = "HIDE";
//changeObjectVisibility('Layer 1', 'hidden')
//delete app.active.document.layers['layer1']
//this_image.layers[2].remove(2);
//curDoc.activeLayer = curDoc.layers[curDoc.layers.length-1];
//curDoc.activeLayer.remove(); curDoc.mergeVisibleLayers();


// ++++++++++ The actual script stops here ++++++++++



//========RotatePortraits2B.js ENDS HERE=========
Andrew

Script to rotate portrait photos 90 to allow resize thenback

Post by Andrew »

Hi Philip

There's nothing I can see that is actually wrong with your script - what happens when it doesn't work? A better way of doing this is to have the script do the resizing itself based on orientation, or alternatively have the script choose one of two resizing actions to use based on orientation (assuming automate>>fit image is not an option for the situation) - you can then edit the actions whenever you wish or even select to open the action settings dialog.

Andrew[/code]