Auto crop after rotate

Discussion in 'Photoshop Tutorials' started by Denis Perelyubskiy, Jul 12, 2005.

  1. 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
     
    Denis Perelyubskiy, Jul 12, 2005
    #1
    1. Advertisements

  2. 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.

    Bye for now,

    George Dingwall

    Invergordon, Scotland

    www.georgedingwall.freeuk.com
     
    George Dingwall, Jul 12, 2005
    #2
    1. Advertisements

  3. 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
     
    Denis Perelyubskiy, Jul 12, 2005
    #3
  4. Hi Denis,

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

    Good luck.

    Bye for now,

    George Dingwall

    Invergordon, Scotland

    www.georgedingwall.freeuk.com
     
    George Dingwall, Jul 12, 2005
    #4
  5. Denis Perelyubskiy

    Mister Max Guest

    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
     
    Mister Max, Jul 12, 2005
    #5
  6. Hello,
    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
     
    Denis Perelyubskiy, Jul 13, 2005
    #6
  7. 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();


    Bye for now,

    George Dingwall

    Invergordon, Scotland

    www.georgedingwall.freeuk.com
     
    George Dingwall, Jul 14, 2005
    #7
  8. 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.
     
    Denis Perelyubskiy, Jul 15, 2005
    #8
  9. Denis Perelyubskiy

    Mister Max Guest

    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;"


    --
    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
     
    Mister Max, Jul 15, 2005
    #9
  10. 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.

    Bye for now,

    George Dingwall

    Invergordon, Scotland

    www.georgedingwall.freeuk.com
     
    George Dingwall, Jul 16, 2005
    #10
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.