Hi
on my laptop i run xp adn photoshop cs3 normal (not extended)
what i miss is a good straighten and crop like cs5
in cs3 i use the ruler tool ->rotate canvas -> arbitrary
and i my photo is straight but with big borders around the photo
now cs5 does a great job
but photoshop cs3 no
there is the scipt straighten and crop photos but in this case doesn't do a great job
because delete the borders and my photo returns to be awry
ok i can crop manually , but it's exhausting if i have to work on some photos , one by one
is there a script/action/tips or plugin that can do the same great cs5 job?
thanks
cheers
Before Adobe added that feature, I always had to do the crop manually. I agree, it's a nice feature in the newest Photoshop.
There's a possibility someone made a script for it I suppose, but I don't recall hearing of one.
Do you have a Photoshop CS5 license? Did you know you're allowed to install it on two computers (e.g., your desktop and your laptop)?
-Noel
hi Noel
i would like to keep cs3 on my laptop
cs5 need a faster pc
but for example cs3 camera can do it
but is there a script to fit the crop ?
i mean after i straighten the photo , but i have the background color
a script could detect the background color and fit the crop
the background color could easily changed by a script
is there around a fit the crop or fit to crop?
thanks
cheers
This script has been around for a long time and might fit your needs?
// ================================================================================================
// Script Name: autocrop.js
// ================================================================================================
// Version 2.0 9 December 2003
// Description: crops the active document after image rotation
// This version is compatible with Photoshop CS and will not run on Photoshop 7
// This script is product of Paul Jaruszewski and Roger Cavanagh
// Contact Paul at www.melor.com
// Contact Roger at www.rogercavanagh.com
// This script is provided free for personal use.
// No liability will be accepted for any consequences arising from the use of this script.
// This script may be copied IN ITS ENTIRETY to others provided and no charge is made other
// than for media. Credit to Paul and Roger must be made if this script is posted for download
// or distribution.
// Installation: copy the file autocrop.js to the ..\Presets\Scripts folder
// Globals
var chosenMethod = 0;
var ui_NoOpenDocuement = "No open document";
var hlpMsg = new Array();
var msg = "";
var hid_BinChop = 1;
msg = "Binary Search will usually be the fastest method to find edges, but may be slower than the ";
msg = msg + "Slice method with smaller amounts (1-2 degrees) of rotation. May produce an over";
msg = msg + "-crop, if the search inadvertently matches the background colour inside the picture.";
hlpMsg[hid_BinChop] = msg;
var hid_Slice = 2;
msg = "Almost as fast as binary search method, but will sometimes produce slight over-crop. This ";
msg = msg + "can be avoided by ensuring the background colour is different from the edges (10 px) ";
msg = msg + "colour in the picture";
hlpMsg[hid_Slice] = msg;
var hid_UniPixel = 3;
msg = "This is much the slowest search method, but will only produce an error, ";
msg = msg + "if edges pixels are the same colour as the background.";
hlpMsg[hid_UniPixel] = msg;
var hid_BestResults = 4;
msg = "For best results, you should make sure the background colour does not occur near the top ";
msg = msg + "left corner of your picture. If the picture contains predominantly dark colours, ";
msg = msg + "set a white background before image rotation, and vice versa.";
hlpMsg[hid_BestResults] = msg;
// ================================================================================================
function settingDialog() { // Creates dialog window and gets user input ===settingDialog===
// ================================================================================================
// These are functions in scope for settingDialog ()
// ------------------------------------------------------------------------------aboutBtnOnClick---
function aboutBtnOnClick() {
var msg = "Autocrop V2\n\n\Copyright \u00A9 2003 Paul Jaruszewski and Roger Cavanagh\n";
msg = msg + "www.melor.com - www.rogercavanagh.com\n";
msg = msg + "Information: http://www.rogercavanagh.com/actions/15_autocrop.htm";
dlg.msgPnl.helpMsgSt.text = msg;
} // end about BtnOnClick
function cancelBtnOnClick() { // -----------------------------------------------cancelBtnOnClick---
dlg.close();
} // end cancelBtnOnClick
function evalMethod() { //------------------------------------------------------------evalMethod---
var result = 0;
if (dlg.methodPnl.binChop.value) { result = 1; };
if (dlg.methodPnl.slice.value) { result = 2; };
if (dlg.methodPnl.uniPixel.value) { result = 3; };
return result;
} // end function evalMethod
function runBtnOnClick() { // -----------------------------------------------------runBtnOnClick---
chosenMethod = evalMethod();
dlg.close();
} // end runBtnOnClick
function displayHelp(hlpMsgId) { // -------------------------------------------------displayHelp---
dlg.msgPnl.helpMsgSt.text = hlpMsg[hlpMsgId];
} // end function
// Standard Values
var mgn = 10;
var mgnTop = 20;
var rowH = 20;
var rBtnW = 120;
var btnW = 100;
// Method Panel Parameters ---Method Panel Parameters---
var ul_MethodPnlTitle= "Method:";
var methodPnlRows = 3;
var methodPnlCols = 1;
var methodPnlH = methodPnlRows*(mgn + rowH) + mgnTop;
var methodPnlW = 350; // (methodPnlRows + 1)*mgn + rBtnW; // max number of items
var methodPnlX = mgn;
var methodPnlY = mgn;
// Control Panel Parameters ---Control Panel Parameters---
var ul_ControlPnlTitle = "Control Panel:";
var ul_Run = "Run";
var ul_Cancel = "Cancel";
var ul_About = "About";
var controlPnlRows = 3;
var controlPnlCols = 1;
var controlPnlH = methodPnlH;
var controlPnlW = btnW + (controlPnlCols + 1)*mgn
var controlPnlX = methodPnlX + methodPnlW + mgn;
var controlPnlY = mgn;
// Message Panel Parameters ---Message Panel Parameters---
var ul_MsgPnlTitle = "";
var msgPnlH = 140;
var msgPnlW = methodPnlW + controlPnlW + mgn;
var msgPnlX = mgn;
var msgPnlY = methodPnlY + methodPnlH + mgn;
var ul_BinarySearch = "Binary Search";
var ul_PixelSlice = "Pixel Slice";
var ul_SinglePixel = "Single Pixel";
// Dialog Window Parameters ---Dialog Window Parameters---
var uiTitle = "Autocrop";
var numPnlsAcross = 2;
var numPnlsDown = 2;
var dlgX = 100;
var dlgY = 100;
var dlgH = methodPnlH + msgPnlH + (numPnlsDown + 1)*mgn;
var dlgW = methodPnlW + controlPnlW + (numPnlsAcross + 1)*mgn;
var bounds = new Array(4);
var x1 = 0, x2 = 0, y1 = 0;
// Create window and panels ---Create window and panels---
bounds = {x:dlgX, y:dlgY, width:dlgW, height:dlgH};
var dlg = new Window("dialog", uiTitle, bounds);
bounds = {x:methodPnlX, y:methodPnlY, width:methodPnlW, height:methodPnlH};
dlg.methodPnl = dlg.add("panel", bounds, ul_MethodPnlTitle);
bounds = {x:controlPnlX, y:controlPnlY, width:controlPnlW, height:controlPnlH};
dlg.controlPnl = dlg.add("panel", bounds, "Control Panel:");
// Method Panel Elements ---Method Panel Elements---
x1 = mgn;
y1 = mgnTop;
bounds = {x:x1, y:y1, width:rBtnW, height:rowH};
dlg.methodPnl.binChop = dlg.methodPnl.add("radiobutton", bounds, ul_BinarySearch);
dlg.methodPnl.binChop.value = true;
dlg.methodPnl.binChop.onClick = function() { displayHelp(hid_BinChop); };
y1 = y1 + rowH +mgn;
bounds = {x:x1, y:y1, width:rBtnW, height:rowH};
dlg.methodPnl.slice = dlg.methodPnl.add("radiobutton", bounds, ul_PixelSlice);
dlg.methodPnl.slice.onClick = function() { displayHelp(hid_Slice); };
y1 = y1 + rowH +mgn;
bounds = {x:x1, y:y1, width:rBtnW, height:rowH};
dlg.methodPnl.uniPixel = dlg.methodPnl.add("radiobutton", bounds, ul_SinglePixel);
dlg.methodPnl.uniPixel.onClick = function() { displayHelp(hid_UniPixel); };
// Control Panel Elements ---Control Panel Elements---
x1 = mgn;
y1 = mgnTop;
bounds = {x:x1, y:y1, width:btnW, height:rowH};
dlg.controlPnl.runBtn = dlg.controlPnl.add("button", bounds, ul_Run);
dlg.controlPnl.runBtn.onClick = function() {runBtnOnClick();};
y1 = y1 + rowH + mgn;
bounds = {x:x1, y:y1, width:btnW, height:rowH};
dlg.controlPnl.cancelBtn = dlg.controlPnl.add("button", bounds, ul_Cancel);
dlg.controlPnl.cancelBtn.onClick = function() {cancelBtnOnClick();};
y1 = y1 + rowH + mgn;
bounds = {x:x1, y:y1, width:btnW, height:rowH};
dlg.controlPnl.aboutBtn = dlg.controlPnl.add("button", bounds, ul_About);
dlg.controlPnl.aboutBtn.onClick = function() {aboutBtnOnClick();};
// Message Panel Elements ---Message Panel Elements---
bounds = {x:msgPnlX, y:msgPnlY, width:msgPnlW, height:msgPnlH};
dlg.msgPnl = dlg.add("panel", bounds, "");
x1 = mgn;
y1 = mgn;
bounds = {x:x1, y:y1, width:msgPnlW - 2*mgn, height:msgPnlH - 2*mgn};
dlg.msgPnl.helpMsgSt = dlg.msgPnl.add("statictext", bounds, "", {multiline: true});
displayHelp(hid_BestResults);
return dlg;
} // end settingDialog ========================================================end settingDialog===
// ================================================================================================
function main() { // ===main===
// ================================================================================================
// These are functions in scope for main()
function doCropUniPixel() { // Single Pixel Search Routine ---------------------doCropUniPixel---
// Declare and Initialise
var picrgb = new Array(3);
var backrgb = new Array(3);
var bounds = new Array(4);
var j = 0;
backrgb=eyeDropper(0,0); //Find color of upper left pixel
var maxi = docRef.width;
if (maxi > docRef.height) {
maxi = docRef.height;
}
maxi = Math.floor(maxi/2);
loopOne:
for (j=1;j < maxi; j++) {
picrgb=eyeDropper(j,j);
if (backrgb[0] != picrgb[0] || backrgb[1] != picrgb[1] || backrgb[2] != picrgb[2]) { // edge!
bounds = new Array(j, j, docRef.width - j, docRef.height - j);
docRef.crop(bounds);
bounds = null;
break; // Exit for loop
}
purge(PurgeTarget.ALLCACHES);
} // end for
// prep for looptwo
var maxi = docRef.width;
if (maxi > docRef.height) {
maxi = docRef.height;
}
maxi = Math.floor(maxi/2);
loopTwo:
for (j=1;j < maxi; j++) {
picrgb=eyeDropper(docRef.width - j,j);
if (backrgb[0] != picrgb[0] || backrgb[1] != picrgb[1] || backrgb[2] != picrgb[2]) { // edge
bounds = new Array(j, j, docRef.width - j, docRef.height - j);
docRef.crop(bounds);
bounds = null;
break; // Exit for loop
}
purge(PurgeTarget.ALLCACHES);
} // end for
} // end function doCropUniPixel
function doCropBinChop() { // Binary Search Routine -----------------------------doCropBinChop---
// Declare and Initialise
var picrgb = new Array(3);
var backrgb = new Array(3);
var bounds = new Array(4);
var j = 0;
var ub= 0;
var lb = 0;
backrgb=eyeDropper(0,0); //Find colour of upper left pixel
var maxi = docRef.width;
if (maxi > docRef.height) {
maxi = docRef.height;
}
ub = Math.floor(maxi/2);
loopOne:
while (ub - lb > 1) {
j = Math.floor((ub - lb)/2) + lb;
picrgb=eyeDropper(j,j);
if (backrgb[0] != picrgb[0] || backrgb[1] != picrgb[1] || backrgb[2] != picrgb[2]) {
ub = j;
} else {
lb = j;
} // end if
purge(PurgeTarget.ALLCACHES);
} // end while
bounds = [ub , ub , docRef.width - ub , docRef.height - ub ];
docRef.crop(bounds);
bounds = null;
// prep for looptwo
maxi = docRef.width;
if (maxi > docRef.height) {
maxi = docRef.height;
}
lb = 0;
ub = Math.floor(maxi/2)
loopTwo:
while (ub - lb > 1) {
j = Math.floor((ub - lb)/2) + lb;
picrgb=eyeDropper(docRef.width - j,j);
if (backrgb[0] != picrgb[0] || backrgb[1] != picrgb[1] || backrgb[2] != picrgb[2]) {
ub = j;
} else {
lb = j;
} // end if
purge(PurgeTarget.ALLCACHES);
} // end while
bounds = [ub , ub , docRef.width - ub , docRef.height - ub];
docRef.crop(bounds);
bounds = null;
} // end function doCropBinChop
function doCropSlice() { // +10 Pixel Routine ---------------------------------------doCropSlice---
// Declare and Initialise
var picrgb = new Array(3);
var backrgb = new Array(3);
var bounds = new Array(4);
var j = 0;
var jInc = 10;
var maxi = docRef.width;
if (maxi > docRef.height) {
maxi = docRef.height;
}
backrgb=eyeDropper(0,0); //Find colour of upper left pixel
j = 1;
loopOne:
while (j < maxi) {
picrgb=eyeDropper(j,j);
if (backrgb[0] != picrgb[0] || backrgb[1] != picrgb[1] || backrgb[2] != picrgb[2]) {
if (jInc == 1) {
bounds = [j, j, docRef.width - j, docRef.height - j];
docRef.crop(bounds);
bounds = null;
break loopOne;
} else {
j = j - jInc;
if (j < 0) {
j = 0;
}
jInc = 1 ;
}
}
purge(PurgeTarget.ALLCACHES);
j = j + jInc;
} // end while
maxi = docRef.width;
if (maxi > docRef.height) {
maxi = docRef.height;
}
jInc = 5;
j = 1;
loopTwo:
while (j < maxi) {
picrgb=eyeDropper(docRef.width - j,j);
if (backrgb[0] != picrgb[0] || backrgb[1] != picrgb[1] || backrgb[2] != picrgb[2]) {
if (jInc == 1) {
bounds = [j, j, docRef.width - j, docRef.height - j];
docRef.crop(bounds);
bounds = null;
break loopTwo;
} else {
j = j - jInc;
if (j < 0) {
j = 0;
}
jInc = 1;
}
}
purge(PurgeTarget.ALLCACHES);
j = j + jInc;
} // end while
} // end function doCropSlice
function eyeDropper(x,y) { // --------------------------------------------------------eyeDropper---
// This function returns the three values for the RGB colours of any given pixel
var x2 = x + 1;
var y2 = y + 1;
var out = new Array(3);
docRef.selection.select([[x,y], [x2,y], [x2,y2], [x, y2]], SelectionType.REPLACE, 0, false);
for(ch in list = ["Red", "Green", "Blue"]) {
histogram = docRef.channels[list[ch]].histogram;
for (i = 0; i <= 255; i++) {
if (histogram[i]) {
out[ch] = i;
break;
}
} // end for
} // end for
return out;
} // end function eyeDropper
// ------------------------------------------------------------------------------------------------
// Start of main() processing ---Start of main() processing---
// ------------------------------------------------------------------------------------------------
if ( documents.length <= 0 ) {
alert(ui_NoOpenDocument); // so we crash out
return;
}
try {
var docRef = activeDocument;
var settings = settingDialog(chosenMethod);
settings.show();
switch(chosenMethod) {
case 1:
doCropBinChop();
break;
case 2:
doCropSlice();
break;
case 3:
doCropUniPixel();
break;
} // End switch
} catch (e) {
alert("Something's bollixed. Error name: " + e.name + ". Error message: " + e.message);
} // end try
} // end function main
// ================================================================================================
// Dispatch
// ================================================================================================
main();
That's what the crop and straighten script does...
You could try recording an action, where you select the surrounding area (with a stop in the action) and it would do select>inverse, and then edit>trim.
i did it but doesn't work
i rotated the image , selected all the violet with magic wand tool , select inverse
trim --> it does nothing
You do use Photoshop in Italian?
yes , could be the issue?
You would need to crop the image, in this case, but would miss the relevant parts
i did not understand
i use photoshop cs3 on my laptop not cs5
what's the meaning "in this case, but would miss the relevant parts"?
sorry for my poor english
i would like to auto fit the crop script, in short a crop that anchor at the violet pixel
what should do the script posted?
is the trim in this case unless?
thanks a lot
cheers
Yes, in this case, trim is useless as it already fits the top and bottom and side of the image anyways.
I don't know about the script issue, I was raising it in case it might help Paul troubleshoot the script.
Just in case, How did you try to use the script?
What I meant by missing the relevant parts, is that the passage would be severely cropped to fit the edges, given the strong rotation.
mantralightroom wrote:
i would like to keep cs3 on my laptop
cs5 need a faster pc
That's an interesting thought. I haven't actually tried running Photoshop CS5 on an older PC, but I never noticed that it seemed any more sluggish than its predecessors. Did you actually try it, or are you just assuming it would be too slow?
I should think Photoshop CS5 would run just about the same as Photoshop CS3 if you disable OpenGL Drawing (assuming it can even try to enable itself on your laptop).
-Noel
Did you actually try it, or are you just assuming it would be too slow?
no i did not try it
I should think Photoshop CS5 would run just about the same as Photoshop CS3 if you disable OpenGL Drawing
i guess that the OpenGL Drawing should give more power to the cpu , is it right?
did you try cs6 beta version ? is like cs5 or need more resource?
but my screenshot, is hard to find or adapt a script that fit the crop using for example the violet pixel like anchors?
Photoshop CS6 is not yet available.
It's possible, depending on your laptop, that OpenGL Drawing will be available and work well enough. But if it doesn't the fallback is to manage the screen displays in the same manner as Photoshop CS3, using GDI functionality.
From what I gather you haven't had much luck so far in adapting a script to bring Photoshop CS5 functionality into CS3. That's the reason I suggested considering installing the software you already have a license for.
-Noel
hi Kelly
there are 2 scipts
http://www.melor.com/projects/autocrop_info.htm
v1
http://www.melor.com/projects/scripts/autocrop.js
that works good , i mean it autocrop
v2
http://www.melor.com/projects/scripts/autocropv2.js
the dialog works but i doesn't crop well in all the 3 option
does the v2 crop good to you?
thanks
cheers
Both versions work good on most images, but i couldn't really get a good test on your screenshot.
You can try the scripts on this image as all the settings in the v2 work on this image as well as v1. (this is the only image i had that came close to yours in terms of colors)
https://acrobat.com/#d=bLrN2-PPlmGJacISa1pu9A
Added: I should also say that the v2 script doesn't work very well in cs5, but the v1 seems to work fine.
Message was edited by: R_Kelly
thanks Kelly
image psd tested on photoshp cs3
well script v2 doesn't give me good results
binary search -> bad crop
v2 pixel slice & single pixel , don't crop
v1 seems to works good
the gray is the photoshop background ,50% gray
in short kelly under cs3 all the 2 scripts with all the settings give you a good crop , right?
instaed cs5 no
cheers
thanks a lot
Yes, in cs3 both scripts work on that photo, but the difference could be either because your language version is different or your on a mac.
I'm using windows english and i don't have cs3 on a mac to test. Perhaps someone else that is using cs3 on a mac will verify whether the script v2 works for them.
And yes the v2 script doesn't seem to work very well on windows cs5. (i get the same results in cs5 as you do in cs3 with the v2 script, but you don't need it in cs5)
If the v1 script works for you, then i would just use that. And if you make an action for rotate and crop, then you wouldn't have to deal with the dialog, which is a plus.
This sets the rulerunits to Pixels then when finished resets them back to what they were....
// ================================================================================================
// Script Name: autocrop.js
// ================================================================================================
// Version 2.0 9 December 2003
// Description: crops the active document after image rotation
// This version is compatible with Photoshop CS and will not run on Photoshop 7
// This script is product of Paul Jaruszewski and Roger Cavanagh
// Contact Paul at www.melor.com
// Contact Roger at www.rogercavanagh.com
// This script is provided free for personal use.
// No liability will be accepted for any consequences arising from the use of this script.
// This script may be copied IN ITS ENTIRETY to others provided and no charge is made other
// than for media. Credit to Paul and Roger must be made if this script is posted for download
// or distribution.
// Installation: copy the file autocrop.js to the ..\Presets\Scripts folder
// Globals
var chosenMethod = 0;
var ui_NoOpenDocuement = "No open document";
var hlpMsg = new Array();
var msg = "";
var hid_BinChop = 1;
msg = "Binary Search will usually be the fastest method to find edges, but may be slower than the ";
msg = msg + "Slice method with smaller amounts (1-2 degrees) of rotation. May produce an over";
msg = msg + "-crop, if the search inadvertently matches the background colour inside the picture.";
hlpMsg[hid_BinChop] = msg;
var hid_Slice = 2;
msg = "Almost as fast as binary search method, but will sometimes produce slight over-crop. This ";
msg = msg + "can be avoided by ensuring the background colour is different from the edges (10 px) ";
msg = msg + "colour in the picture";
hlpMsg[hid_Slice] = msg;
var hid_UniPixel = 3;
msg = "This is much the slowest search method, but will only produce an error, ";
msg = msg + "if edges pixels are the same colour as the background.";
hlpMsg[hid_UniPixel] = msg;
var hid_BestResults = 4;
msg = "For best results, you should make sure the background colour does not occur near the top ";
msg = msg + "left corner of your picture. If the picture contains predominantly dark colours, ";
msg = msg + "set a white background before image rotation, and vice versa.";
hlpMsg[hid_BestResults] = msg;
// ================================================================================================
function settingDialog() { // Creates dialog window and gets user input ===settingDialog===
// ================================================================================================
// These are functions in scope for settingDialog ()
// ------------------------------------------------------------------------------aboutBtnOnClick---
function aboutBtnOnClick() {
var msg = "Autocrop V2\n\n\Copyright \u00A9 2003 Paul Jaruszewski and Roger Cavanagh\n";
msg = msg + "www.melor.com - www.rogercavanagh.com\n";
msg = msg + "Information: http://www.rogercavanagh.com/actions/15_autocrop.htm";
dlg.msgPnl.helpMsgSt.text = msg;
} // end about BtnOnClick
function cancelBtnOnClick() { // -----------------------------------------------cancelBtnOnClick---
dlg.close();
} // end cancelBtnOnClick
function evalMethod() { //------------------------------------------------------------evalMethod---
var result = 0;
if (dlg.methodPnl.binChop.value) { result = 1; };
if (dlg.methodPnl.slice.value) { result = 2; };
if (dlg.methodPnl.uniPixel.value) { result = 3; };
return result;
} // end function evalMethod
function runBtnOnClick() { // -----------------------------------------------------runBtnOnClick---
chosenMethod = evalMethod();
dlg.close();
} // end runBtnOnClick
function displayHelp(hlpMsgId) { // -------------------------------------------------displayHelp---
dlg.msgPnl.helpMsgSt.text = hlpMsg[hlpMsgId];
} // end function
// Standard Values
var mgn = 10;
var mgnTop = 20;
var rowH = 20;
var rBtnW = 120;
var btnW = 100;
// Method Panel Parameters ---Method Panel Parameters---
var ul_MethodPnlTitle= "Method:";
var methodPnlRows = 3;
var methodPnlCols = 1;
var methodPnlH = methodPnlRows*(mgn + rowH) + mgnTop;
var methodPnlW = 350; // (methodPnlRows + 1)*mgn + rBtnW; // max number of items
var methodPnlX = mgn;
var methodPnlY = mgn;
// Control Panel Parameters ---Control Panel Parameters---
var ul_ControlPnlTitle = "Control Panel:";
var ul_Run = "Run";
var ul_Cancel = "Cancel";
var ul_About = "About";
var controlPnlRows = 3;
var controlPnlCols = 1;
var controlPnlH = methodPnlH;
var controlPnlW = btnW + (controlPnlCols + 1)*mgn
var controlPnlX = methodPnlX + methodPnlW + mgn;
var controlPnlY = mgn;
// Message Panel Parameters ---Message Panel Parameters---
var ul_MsgPnlTitle = "";
var msgPnlH = 140;
var msgPnlW = methodPnlW + controlPnlW + mgn;
var msgPnlX = mgn;
var msgPnlY = methodPnlY + methodPnlH + mgn;
var ul_BinarySearch = "Binary Search";
var ul_PixelSlice = "Pixel Slice";
var ul_SinglePixel = "Single Pixel";
// Dialog Window Parameters ---Dialog Window Parameters---
var uiTitle = "Autocrop";
var numPnlsAcross = 2;
var numPnlsDown = 2;
var dlgX = 100;
var dlgY = 100;
var dlgH = methodPnlH + msgPnlH + (numPnlsDown + 1)*mgn;
var dlgW = methodPnlW + controlPnlW + (numPnlsAcross + 1)*mgn;
var bounds = new Array(4);
var x1 = 0, x2 = 0, y1 = 0;
// Create window and panels ---Create window and panels---
bounds = {x:dlgX, y:dlgY, width:dlgW, height:dlgH};
var dlg = new Window("dialog", uiTitle, bounds);
bounds = {x:methodPnlX, y:methodPnlY, width:methodPnlW, height:methodPnlH};
dlg.methodPnl = dlg.add("panel", bounds, ul_MethodPnlTitle);
bounds = {x:controlPnlX, y:controlPnlY, width:controlPnlW, height:controlPnlH};
dlg.controlPnl = dlg.add("panel", bounds, "Control Panel:");
// Method Panel Elements ---Method Panel Elements---
x1 = mgn;
y1 = mgnTop;
bounds = {x:x1, y:y1, width:rBtnW, height:rowH};
dlg.methodPnl.binChop = dlg.methodPnl.add("radiobutton", bounds, ul_BinarySearch);
dlg.methodPnl.binChop.value = true;
dlg.methodPnl.binChop.onClick = function() { displayHelp(hid_BinChop); };
y1 = y1 + rowH +mgn;
bounds = {x:x1, y:y1, width:rBtnW, height:rowH};
dlg.methodPnl.slice = dlg.methodPnl.add("radiobutton", bounds, ul_PixelSlice);
dlg.methodPnl.slice.onClick = function() { displayHelp(hid_Slice); };
y1 = y1 + rowH +mgn;
bounds = {x:x1, y:y1, width:rBtnW, height:rowH};
dlg.methodPnl.uniPixel = dlg.methodPnl.add("radiobutton", bounds, ul_SinglePixel);
dlg.methodPnl.uniPixel.onClick = function() { displayHelp(hid_UniPixel); };
// Control Panel Elements ---Control Panel Elements---
x1 = mgn;
y1 = mgnTop;
bounds = {x:x1, y:y1, width:btnW, height:rowH};
dlg.controlPnl.runBtn = dlg.controlPnl.add("button", bounds, ul_Run);
dlg.controlPnl.runBtn.onClick = function() {runBtnOnClick();};
y1 = y1 + rowH + mgn;
bounds = {x:x1, y:y1, width:btnW, height:rowH};
dlg.controlPnl.cancelBtn = dlg.controlPnl.add("button", bounds, ul_Cancel);
dlg.controlPnl.cancelBtn.onClick = function() {cancelBtnOnClick();};
y1 = y1 + rowH + mgn;
bounds = {x:x1, y:y1, width:btnW, height:rowH};
dlg.controlPnl.aboutBtn = dlg.controlPnl.add("button", bounds, ul_About);
dlg.controlPnl.aboutBtn.onClick = function() {aboutBtnOnClick();};
// Message Panel Elements ---Message Panel Elements---
bounds = {x:msgPnlX, y:msgPnlY, width:msgPnlW, height:msgPnlH};
dlg.msgPnl = dlg.add("panel", bounds, "");
x1 = mgn;
y1 = mgn;
bounds = {x:x1, y:y1, width:msgPnlW - 2*mgn, height:msgPnlH - 2*mgn};
dlg.msgPnl.helpMsgSt = dlg.msgPnl.add("statictext", bounds, "", {multiline: true});
displayHelp(hid_BestResults);
return dlg;
} // end settingDialog ========================================================end settingDialog===
// ================================================================================================
function main() { // ===main===
// ================================================================================================
// These are functions in scope for main()
function doCropUniPixel() { // Single Pixel Search Routine ---------------------doCropUniPixel---
// Declare and Initialise
var picrgb = new Array(3);
var backrgb = new Array(3);
var bounds = new Array(4);
var j = 0;
backrgb=eyeDropper(0,0); //Find color of upper left pixel
var maxi = docRef.width;
if (maxi > docRef.height) {
maxi = docRef.height;
}
maxi = Math.floor(maxi/2);
loopOne:
for (j=1;j < maxi; j++) {
picrgb=eyeDropper(j,j);
if (backrgb[0] != picrgb[0] || backrgb[1] != picrgb[1] || backrgb[2] != picrgb[2]) { // edge!
bounds = new Array(j, j, docRef.width - j, docRef.height - j);
docRef.crop(bounds);
bounds = null;
break; // Exit for loop
}
purge(PurgeTarget.ALLCACHES);
} // end for
// prep for looptwo
var maxi = docRef.width;
if (maxi > docRef.height) {
maxi = docRef.height;
}
maxi = Math.floor(maxi/2);
loopTwo:
for (j=1;j < maxi; j++) {
picrgb=eyeDropper(docRef.width - j,j);
if (backrgb[0] != picrgb[0] || backrgb[1] != picrgb[1] || backrgb[2] != picrgb[2]) { // edge
bounds = new Array(j, j, docRef.width - j, docRef.height - j);
docRef.crop(bounds);
bounds = null;
break; // Exit for loop
}
purge(PurgeTarget.ALLCACHES);
} // end for
} // end function doCropUniPixel
function doCropBinChop() { // Binary Search Routine -----------------------------doCropBinChop---
// Declare and Initialise
var picrgb = new Array(3);
var backrgb = new Array(3);
var bounds = new Array(4);
var j = 0;
var ub= 0;
var lb = 0;
backrgb=eyeDropper(0,0); //Find colour of upper left pixel
var maxi = docRef.width;
if (maxi > docRef.height) {
maxi = docRef.height;
}
ub = Math.floor(maxi/2);
loopOne:
while (ub - lb > 1) {
j = Math.floor((ub - lb)/2) + lb;
picrgb=eyeDropper(j,j);
if (backrgb[0] != picrgb[0] || backrgb[1] != picrgb[1] || backrgb[2] != picrgb[2]) {
ub = j;
} else {
lb = j;
} // end if
purge(PurgeTarget.ALLCACHES);
} // end while
bounds = [ub , ub , docRef.width - ub , docRef.height - ub ];
docRef.crop(bounds);
bounds = null;
// prep for looptwo
maxi = docRef.width;
if (maxi > docRef.height) {
maxi = docRef.height;
}
lb = 0;
ub = Math.floor(maxi/2)
loopTwo:
while (ub - lb > 1) {
j = Math.floor((ub - lb)/2) + lb;
picrgb=eyeDropper(docRef.width - j,j);
if (backrgb[0] != picrgb[0] || backrgb[1] != picrgb[1] || backrgb[2] != picrgb[2]) {
ub = j;
} else {
lb = j;
} // end if
purge(PurgeTarget.ALLCACHES);
} // end while
bounds = [ub , ub , docRef.width - ub , docRef.height - ub];
docRef.crop(bounds);
bounds = null;
} // end function doCropBinChop
function doCropSlice() { // +10 Pixel Routine ---------------------------------------doCropSlice---
// Declare and Initialise
var picrgb = new Array(3);
var backrgb = new Array(3);
var bounds = new Array(4);
var j = 0;
var jInc = 10;
var maxi = docRef.width;
if (maxi > docRef.height) {
maxi = docRef.height;
}
backrgb=eyeDropper(0,0); //Find colour of upper left pixel
j = 1;
loopOne:
while (j < maxi) {
picrgb=eyeDropper(j,j);
if (backrgb[0] != picrgb[0] || backrgb[1] != picrgb[1] || backrgb[2] != picrgb[2]) {
if (jInc == 1) {
bounds = [j, j, docRef.width - j, docRef.height - j];
docRef.crop(bounds);
bounds = null;
break loopOne;
} else {
j = j - jInc;
if (j < 0) {
j = 0;
}
jInc = 1 ;
}
}
purge(PurgeTarget.ALLCACHES);
j = j + jInc;
} // end while
maxi = docRef.width;
if (maxi > docRef.height) {
maxi = docRef.height;
}
jInc = 5;
j = 1;
loopTwo:
while (j < maxi) {
picrgb=eyeDropper(docRef.width - j,j);
if (backrgb[0] != picrgb[0] || backrgb[1] != picrgb[1] || backrgb[2] != picrgb[2]) {
if (jInc == 1) {
bounds = [j, j, docRef.width - j, docRef.height - j];
docRef.crop(bounds);
bounds = null;
break loopTwo;
} else {
j = j - jInc;
if (j < 0) {
j = 0;
}
jInc = 1;
}
}
purge(PurgeTarget.ALLCACHES);
j = j + jInc;
} // end while
} // end function doCropSlice
function eyeDropper(x,y) { // --------------------------------------------------------eyeDropper---
// This function returns the three values for the RGB colours of any given pixel
var x2 = x + 1;
var y2 = y + 1;
var out = new Array(3);
docRef.selection.select([[x,y], [x2,y], [x2,y2], [x, y2]], SelectionType.REPLACE, 0, false);
for(ch in list = ["Red", "Green", "Blue"]) {
histogram = docRef.channels[list[ch]].histogram;
for (i = 0; i <= 255; i++) {
if (histogram[i]) {
out[ch] = i;
break;
}
} // end for
} // end for
return out;
} // end function eyeDropper
// ------------------------------------------------------------------------------------------------
// Start of main() processing ---Start of main() processing---
// ------------------------------------------------------------------------------------------------
if ( documents.length <= 0 ) {
alert(ui_NoOpenDocument); // so we crash out
return;
}
try {
var docRef = activeDocument;
var startRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
var settings = settingDialog(chosenMethod);
settings.show();
switch(chosenMethod) {
case 1:
doCropBinChop();
break;
case 2:
doCropSlice();
break;
case 3:
doCropUniPixel();
break;
} // End switch
app.preferences.rulerUnits = startRulerUnits;
} catch (e) {
app.preferences.rulerUnits = startRulerUnits;
alert("Something's bollixed. Error name: " + e.name + ". Error message: " + e.message + " Line number = " +e.line);
} // end try
} // end function main
// ================================================================================================
// Dispatch
// ================================================================================================
main();
North America
Europe, Middle East and Africa
Asia Pacific