Auto crop after rotate

DP
Posted By
Denis Perelyubskiy
Jul 12, 2005
Views
787
Replies
9
Status
Closed
Hello,

I searched, but did not find the answer, so forgive me if this has been asked.

After I rotate canvas, I want to automagically crop. Let’s say I rotated clockwise. I would like to crop with left border through upper-left, right border through lower-right, upper horizontal border through upper-right, and lower horizontal through lower left corners.

I don’t mind setting background color to something that is guaranteed to stand out from the picture, if photoshop could use this information to determine where picture ends and background begins.

I know one can rotate a crop selection, and this will auto crop and rotate, but I can’t get used to this method.

Is there a plugin, action, etc that would allow me to accomplish this auto-crop task?

thanks!

denis

Master Retouching Hair

Learn how to rescue details, remove flyaways, add volume, and enhance the definition of hair in any photo. We break down every tool and technique in Photoshop to get picture-perfect hair, every time.

GD
George Dingwall
Jul 12, 2005
Hi Denis,

If your using Photoshop CS ( not CS2) , you can get a script from Adobe Share Studio which will do what you want to do. It might also work with version 7 with the scripting plugin, but I’ve never used it with that version.

Go to this link and then select Photoshop/Scripts. In the scripts section look for a script named Autocrop.

Hope this helps.

On Mon, 11 Jul 2005 21:17:14 -0700, Denis Perelyubskiy
wrote:

Hello,

I searched, but did not find the answer, so forgive me if this has been asked.

After I rotate canvas, I want to automagically crop. Let’s say I rotated clockwise. I would like to crop with left border through upper-left, right border through lower-right, upper horizontal border through upper-right, and lower horizontal through lower left corners.
I don’t mind setting background color to something that is guaranteed to stand out from the picture, if photoshop could use this information to determine where picture ends and background begins.

I know one can rotate a crop selection, and this will auto crop and rotate, but I can’t get used to this method.

Is there a plugin, action, etc that would allow me to accomplish this auto-crop task?

thanks!

denis

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com
DP
Denis Perelyubskiy
Jul 12, 2005
Hello. Got it. THANKS!

There is a javascript source, so while I use CS2, I think this will be a great starting point. I could probably take it from here (or maybe it will just work… cause things always do, right? 😉 ).

This has been a MAJOR annoyance of mine ever since I started using Photoshop 🙂 thanks again!

denis

George Dingwall wrote:
Hi Denis,

If your using Photoshop CS ( not CS2) , you can get a script from Adobe Share Studio which will do what you want to do. It might also work with version 7 with the scripting plugin, but I’ve never used it with that version.

Go to this link and then select Photoshop/Scripts. In the scripts section look for a script named Autocrop.

Hope this helps.

On Mon, 11 Jul 2005 21:17:14 -0700, Denis Perelyubskiy
wrote:

Hello,

I searched, but did not find the answer, so forgive me if this has been asked.

After I rotate canvas, I want to automagically crop. Let’s say I rotated clockwise. I would like to crop with left border through upper-left, right border through lower-right, upper horizontal border through upper-right, and lower horizontal through lower left corners.
I don’t mind setting background color to something that is guaranteed to stand out from the picture, if photoshop could use this information to determine where picture ends and background begins.

I know one can rotate a crop selection, and this will auto crop and rotate, but I can’t get used to this method.

Is there a plugin, action, etc that would allow me to accomplish this auto-crop task?

thanks!

denis

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com
GD
George Dingwall
Jul 12, 2005
Hi Denis,

If you get it to work on CS2, I’d love to have a copy.

Good luck.

On Tue, 12 Jul 2005 12:21:00 -0700, Denis Perelyubskiy
wrote:

Hello. Got it. THANKS!

There is a javascript source, so while I use CS2, I think this will be a great starting point. I could probably take it from here (or maybe it will just work… cause things always do, right? 😉 ).

This has been a MAJOR annoyance of mine ever since I started using Photoshop 🙂 thanks again!

denis

George Dingwall wrote:
Hi Denis,

If your using Photoshop CS ( not CS2) , you can get a script from Adobe Share Studio which will do what you want to do. It might also work with version 7 with the scripting plugin, but I’ve never used it with that version.

Go to this link and then select Photoshop/Scripts. In the scripts section look for a script named Autocrop.

Hope this helps.

On Mon, 11 Jul 2005 21:17:14 -0700, Denis Perelyubskiy
wrote:

Hello,

I searched, but did not find the answer, so forgive me if this has been asked.

After I rotate canvas, I want to automagically crop. Let’s say I rotated clockwise. I would like to crop with left border through upper-left, right border through lower-right, upper horizontal border through upper-right, and lower horizontal through lower left corners.
I don’t mind setting background color to something that is guaranteed to stand out from the picture, if photoshop could use this information to determine where picture ends and background begins.

I know one can rotate a crop selection, and this will auto crop and rotate, but I can’t get used to this method.

Is there a plugin, action, etc that would allow me to accomplish this auto-crop task?

thanks!

denis

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com
MM
Mister Max
Jul 12, 2005
George Dingwall posted:

Hi Denis,

If you get it to work on CS2, I’d love to have a copy.

I’d love one too!
– Max


MisterMax

http://buten.net/max/
Slideshows of Angkor Wat, Bali, Crete, France, Malaysia, Maui, Morocco, Mt Holly, Myanmar (new), Sicily, St Tropez, Singapore, Thailand (new), Tour de France.

http://pbase.com/mistermax – Shadows and Reflections
DP
Denis Perelyubskiy
Jul 13, 2005
Hello,

If you get it to work on CS2, I’d love to have a copy.

I almost did 🙂 I tried the binary method, and it actually cropped something for me, but not until I made a rather small change. Then I got stuck, thinking that I came up with a better way to figure out corner locations (tried computing them based on bounds of selections, since you can grow a selection of background color).

In the meantime, one problem I immediately noticed (and the one that stopped the script from executing for me) was that the script would only work if your ruler is set to PIXEL units. If the script does not work for you, try changing ruler units to pixels.

If this takes care of the problem, I can tell you how to modify the script (or will just post an updated script somewhere. It takes all of 4 lines of code) to not have to change units manually while I figure out if I can change the algorithm.

denis

George Dingwall wrote:
Hi Denis,

If you get it to work on CS2, I’d love to have a copy.

Good luck.

On Tue, 12 Jul 2005 12:21:00 -0700, Denis Perelyubskiy
wrote:

Hello. Got it. THANKS!

There is a javascript source, so while I use CS2, I think this will be a great starting point. I could probably take it from here (or maybe it will just work… cause things always do, right? 😉 ).

This has been a MAJOR annoyance of mine ever since I started using Photoshop 🙂 thanks again!

denis

George Dingwall wrote:

Hi Denis,

If your using Photoshop CS ( not CS2) , you can get a script from Adobe Share Studio which will do what you want to do. It might also work with version 7 with the scripting plugin, but I’ve never used it with that version.

Go to this link and then select Photoshop/Scripts. In the scripts section look for a script named Autocrop.

Hope this helps.

On Mon, 11 Jul 2005 21:17:14 -0700, Denis Perelyubskiy
wrote:

Hello,

I searched, but did not find the answer, so forgive me if this has been asked.

After I rotate canvas, I want to automagically crop. Let’s say I rotated clockwise. I would like to crop with left border through upper-left, right border through lower-right, upper horizontal border through upper-right, and lower horizontal through lower left corners.
I don’t mind setting background color to something that is guaranteed to stand out from the picture, if photoshop could use this information to determine where picture ends and background begins.

I know one can rotate a crop selection, and this will auto crop and rotate, but I can’t get used to this method.

Is there a plugin, action, etc that would allow me to accomplish this auto-crop task?

thanks!

denis

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com
GD
George Dingwall
Jul 14, 2005
Hi Denis,

I’ve managed to get the script to work at last.

I’ve added in a few lines of code from another script that sets the ruler units to pixels and then restores the ruler units to their original setting after the script runs.

The following block of code is at the end of the script. I’ve added the lines needed to make the script work Anyone who’s interested can either add in the lines manually, or just copy the whole block into the script and replace the original block.

I’m not a scripting expert, so what I suggest may not be the most elegant solution, but it does work.

//
———————————————————— ———————————— // Start of main() processing
—Start of main() processing—
//
———————————————————— ————————————

if ( documents.length <= 0 ) {
alert(ui_NoOpenDocument); // so we crash out
return;
}
// add the next 2 lines to the AutocropV2 script

var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

//
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);
throw e;
} // end try

//Add the following line to the AutocropV2 Script

preferences.rulerUnits = originalRulerUnits;

//
} // end function main

//
============================================================ ==================================== // Dispatch
//
============================================================ ====================================

main();

On Wed, 13 Jul 2005 11:21:24 -0700, Denis Perelyubskiy
wrote:

Hello,

If you get it to work on CS2, I’d love to have a copy.

I almost did 🙂 I tried the binary method, and it actually cropped something for me, but not until I made a rather small change. Then I got stuck, thinking that I came up with a better way to figure out corner locations (tried computing them based on bounds of selections, since you can grow a selection of background color).

In the meantime, one problem I immediately noticed (and the one that stopped the script from executing for me) was that the script would only work if your ruler is set to PIXEL units. If the script does not work for you, try changing ruler units to pixels.

If this takes care of the problem, I can tell you how to modify the script (or will just post an updated script somewhere. It takes all of 4 lines of code) to not have to change units manually while I figure out if I can change the algorithm.

denis

George Dingwall wrote:
Hi Denis,

If you get it to work on CS2, I’d love to have a copy.

Good luck.

On Tue, 12 Jul 2005 12:21:00 -0700, Denis Perelyubskiy
wrote:

Hello. Got it. THANKS!

There is a javascript source, so while I use CS2, I think this will be a great starting point. I could probably take it from here (or maybe it will just work… cause things always do, right? 😉 ).

This has been a MAJOR annoyance of mine ever since I started using Photoshop 🙂 thanks again!

denis

George Dingwall wrote:

Hi Denis,

If your using Photoshop CS ( not CS2) , you can get a script from Adobe Share Studio which will do what you want to do. It might also work with version 7 with the scripting plugin, but I’ve never used it with that version.

Go to this link and then select Photoshop/Scripts. In the scripts section look for a script named Autocrop.

Hope this helps.

On Mon, 11 Jul 2005 21:17:14 -0700, Denis Perelyubskiy
wrote:

Hello,

I searched, but did not find the answer, so forgive me if this has been asked.

After I rotate canvas, I want to automagically crop. Let’s say I rotated clockwise. I would like to crop with left border through upper-left, right border through lower-right, upper horizontal border through upper-right, and lower horizontal through lower left corners.
I don’t mind setting background color to something that is guaranteed to stand out from the picture, if photoshop could use this information to determine where picture ends and background begins.

I know one can rotate a crop selection, and this will auto crop and rotate, but I can’t get used to this method.

Is there a plugin, action, etc that would allow me to accomplish this auto-crop task?

thanks!

denis

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com
DP
Denis Perelyubskiy
Jul 15, 2005
Hello,

Yeah, I think this is what’s been missing. I am testing an implementation based on a different idea though… just to see if I can do it (I doubt it’ll be very much faster, or anything like that).

Essentially you take one background point (it is in the corner, after the image’s been rotated) and select it; you then proceed to grow selection. Two things may happen here: either only the corner (background that’s showing) is going to get selected, or all background around the image will get selected (since if you rotate twice, for unknown to me reason Photoshop puts padding between image corners and the canvas’ borders). If it’s the latter, you invert your selection and then crop. Now you have an image, whose corners lie on the canvas’ borders.

Again, select a background point and grow selection. Bounding box around the selection will tell us where the corners meet the canvas, and we can execute the crop.

As I said, I don’t know if this is faster or not, but it avoids sampling points alltogether – Photoshop does all the work for us.

Regardless, thanks again for the pointer to the script. Not only did it get me started on photoshop scripting in general, but it’ll save me lots of cropping time!

-d

ps. I wish Javascript support was not as limited; for example, I already figured that I’d much rather drow a crop box – this way if you like the automatic results you just hit enter; if you don’t you move things around a bit… However, I did not find a way to access such function from within the scripting engine.

George Dingwall wrote:
Hi Denis,

I’ve managed to get the script to work at last.

I’ve added in a few lines of code from another script that sets the ruler units to pixels and then restores the ruler units to their original setting after the script runs.

The following block of code is at the end of the script. I’ve added the lines needed to make the script work Anyone who’s interested can either add in the lines manually, or just copy the whole block into the script and replace the original block.

I’m not a scripting expert, so what I suggest may not be the most elegant solution, but it does work.

//
———————————————————— ———————————— // Start of main() processing
—Start of main() processing—
//
———————————————————— ————————————
if ( documents.length <= 0 ) {
alert(ui_NoOpenDocument); // so we crash out
return;
}
// add the next 2 lines to the AutocropV2 script

var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

//
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);
throw e;
} // end try

//Add the following line to the AutocropV2 Script

preferences.rulerUnits = originalRulerUnits;

//
} // end function main

//
============================================================ ==================================== // Dispatch
//
============================================================ ====================================
main();

On Wed, 13 Jul 2005 11:21:24 -0700, Denis Perelyubskiy
wrote:

Hello,

If you get it to work on CS2, I’d love to have a copy.

I almost did 🙂 I tried the binary method, and it actually cropped something for me, but not until I made a rather small change. Then I got stuck, thinking that I came up with a better way to figure out corner locations (tried computing them based on bounds of selections, since you can grow a selection of background color).

In the meantime, one problem I immediately noticed (and the one that stopped the script from executing for me) was that the script would only work if your ruler is set to PIXEL units. If the script does not work for you, try changing ruler units to pixels.

If this takes care of the problem, I can tell you how to modify the script (or will just post an updated script somewhere. It takes all of 4 lines of code) to not have to change units manually while I figure out if I can change the algorithm.

denis

George Dingwall wrote:

Hi Denis,

If you get it to work on CS2, I’d love to have a copy.

Good luck.

On Tue, 12 Jul 2005 12:21:00 -0700, Denis Perelyubskiy
wrote:

Hello. Got it. THANKS!

There is a javascript source, so while I use CS2, I think this will be a great starting point. I could probably take it from here (or maybe it will just work… cause things always do, right? 😉 ).

This has been a MAJOR annoyance of mine ever since I started using Photoshop 🙂 thanks again!

denis

George Dingwall wrote:

Hi Denis,

If your using Photoshop CS ( not CS2) , you can get a script from Adobe Share Studio which will do what you want to do. It might also work with version 7 with the scripting plugin, but I’ve never used it with that version.

Go to this link and then select Photoshop/Scripts. In the scripts section look for a script named Autocrop.

Hope this helps.

On Mon, 11 Jul 2005 21:17:14 -0700, Denis Perelyubskiy
wrote:

Hello,

I searched, but did not find the answer, so forgive me if this has been asked.

After I rotate canvas, I want to automagically crop. Let’s say I rotated clockwise. I would like to crop with left border through upper-left, right border through lower-right, upper horizontal border through upper-right, and lower horizontal through lower left corners.
I don’t mind setting background color to something that is guaranteed to stand out from the picture, if photoshop could use this information to determine where picture ends and background begins.

I know one can rotate a crop selection, and this will auto crop and rotate, but I can’t get used to this method.

Is there a plugin, action, etc that would allow me to accomplish this auto-crop task?

thanks!

denis

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com
MM
Mister Max
Jul 15, 2005
George Dingwall posted:

I’ve managed to get the script to work at last.
The following block of code is at the end of the script. I’ve added the lines needed to make the script work Anyone who’s interested can either add in the lines manually, or just copy the whole block into the script and replace the original block.

I’m not a scripting expert, so what I suggest may not be the most elegant solution, but it does work.

It’s working for me with CS2! Thank you.
Below I have marked a line that seems unnecessary. Should I include it? It’s the line "throw e;"

//
———————————————————— ———– ————————- // Start of main() processing
—Start of main() processing—
//
———————————————————— ———– ————————-

if ( documents.length <= 0 ) {
alert(ui_NoOpenDocument); // so we crash out
return;
}
// add the next 2 lines to the AutocropV2 script

var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

//
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);
throw e; <<<<<<< Is this line necessary or useful???? } // end try

//Add the following line to the AutocropV2 Script

preferences.rulerUnits = originalRulerUnits;

//
} // end function main

//
============================================================ =========== ========================= // Dispatch
//
============================================================ =========== =========================

main();

On Mon, 11 Jul 2005 21:17:14 -0700, Denis Perelyubskiy
wrote:
After I rotate canvas, I want to automagically crop. Let’s say I rotated clockwise. I would like to crop with left border through upper-left, right border through lower-right, upper horizontal border through upper-right, and lower horizontal through lower left corners.
Is there a plugin, action, etc that would allow me to accomplish this auto-crop task?
denis
Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com


MisterMax

http://buten.net/max/
Slideshows of Angkor Wat, Bali, Crete, France, Malaysia, Maui, Morocco, Mt Holly, Myanmar (new), Sicily, St Tropez, Singapore, Thailand (new), Tour de France.

http://pbase.com/mistermax – Shadows and Reflections
GD
George Dingwall
Jul 16, 2005
Hi there,

The line you have marked was in the original script.

I don’t know enough about scripting to know what individual elements are for. If you really want to delete it, put // at the beginningof the line and save it as a copy and then try it. If it still works, it wasn’t needed.

However, I think that "throw e" is part of the error catching section just above it, so it may not give the error message if those conditions are found.

Bye for now.

On Fri, 15 Jul 2005 16:24:17 -0500, Mister Max
wrote:

George Dingwall posted:

I’ve managed to get the script to work at last.
The following block of code is at the end of the script. I’ve added the lines needed to make the script work Anyone who’s interested can either add in the lines manually, or just copy the whole block into the script and replace the original block.

I’m not a scripting expert, so what I suggest may not be the most elegant solution, but it does work.

It’s working for me with CS2! Thank you.
Below I have marked a line that seems unnecessary. Should I include it? It’s the line "throw e;"

//
———————————————————— ———– ————————- // Start of main() processing
—Start of main() processing—
//
———————————————————— ———– ————————-

if ( documents.length <= 0 ) {
alert(ui_NoOpenDocument); // so we crash out
return;
}
// add the next 2 lines to the AutocropV2 script

var originalRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

//
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);
throw e; <<<<<<< Is this line necessary or useful???? } // end try

//Add the following line to the AutocropV2 Script

preferences.rulerUnits = originalRulerUnits;

//
} // end function main

//
============================================================ =========== ========================= // Dispatch
//
============================================================ =========== =========================

main();

On Mon, 11 Jul 2005 21:17:14 -0700, Denis Perelyubskiy
wrote:
After I rotate canvas, I want to automagically crop. Let’s say I rotated clockwise. I would like to crop with left border through upper-left, right border through lower-right, upper horizontal border through upper-right, and lower horizontal through lower left corners.
Is there a plugin, action, etc that would allow me to accomplish this auto-crop task?
denis
Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com

Bye for now,

George Dingwall

Invergordon, Scotland

www.georgedingwall.freeuk.com

Master Retouching Hair

Learn how to rescue details, remove flyaways, add volume, and enhance the definition of hair in any photo. We break down every tool and technique in Photoshop to get picture-perfect hair, every time.

Related Discussion Topics

Nice and short text about related topics in discussion sections