Thanks Thanks:  0
Likes Likes:  0
Dislikes Dislikes:  0
Results 1 to 7 of 7
  1. #1
    Junior Member
    Join Date
    Apr 2017
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Activity
    Points
    55
    Level
    2
    Lv. Percent
    57.67%

    Automated aspect ratio???

    Hey all,


    Just like to say hi, thins is my first post here, I've been wracking my brains over this one. I need to take 100s of jpegs of different sizes and have an action or AppleScript crop them to a specific aspect ratio, say for example 4:3. But I want it to do this regardless of pixel size. So the script would look at the width and then crop the height accordingly to make 4:3


    Any ideas anyone?


    Thanks in advance.


    Scott

  2. #2
    The Script Master
    Join Date
    May 2009
    Location
    Bradford,UK
    Posts
    325
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Activity
    Points
    1,291
    Level
    12
    Lv. Percent
    25.08%
    Achievements Gaining PopularityQualified to FreelanceProfessional Poster
    Awards Scholar

    Re: Automated aspect ratio???

    You can use a script to do this...
    Code:
    #target photoshop;
    app.bringToFront();
    main();
    function main(){
    if(!documents.length) return;
    var strtRulerUnits = app.preferences.rulerUnits;
    app.preferences.rulerUnits = Units.PIXELS;
    var W = activeDocument.width;
    var H = activeDocument.height;
    var ratio = "4:3";
    ratio = ratio.split(":");
    if(W<H) ratio=ratio.reverse();
    var Hpics =(W/Number(ratio[0]))*Number(ratio[1]);
    if(Hpics > H){
        Wpics = (H/Number(ratio[1]))*Number(ratio[0]);
        Hpics = H;
        }else{
            Wpics = W;
            }
    var Left,Top,Right,Bottom=0;
    if (W==Wpics) Left = 0; Right = W; 
    if (W!=Wpics) {
        var diffw = (W-Wpics)/2;
        Left = diffw; Right = Wpics+diffw;
        }
    if (H==Hpics) Top = 0; Bottom = H;
    if( H!=Hpics){
        var diffh = (H-Hpics)/2;
        Top = diffh; Bottom = Hpics+diffh;
        }
    activeDocument.selection.select([[Left,Top],[Right,Top],[Right,Bottom],[Left,Bottom]], SelectionType.REPLACE, 0, false); 
    executeAction(charIDToTypeID( "Crop" ), new ActionDescriptor(), DialogModes.NO );
    activeDocument.selection.deselect();
    app.preferences.rulerUnits = strtRulerUnits;
    };

  3. #3
    Junior Member
    Join Date
    Apr 2017
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Activity
    Points
    55
    Level
    2
    Lv. Percent
    57.67%

    Re: Automated aspect ratio???

    Many many thanks.....

    I've got that loaded in to my scripts, how would I edit this to also do 3:2

    Scott

  4. #4
    The Script Master
    Join Date
    May 2009
    Location
    Bradford,UK
    Posts
    325
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Activity
    Points
    1,291
    Level
    12
    Lv. Percent
    25.08%
    Achievements Gaining PopularityQualified to FreelanceProfessional Poster
    Awards Scholar

    Re: Automated aspect ratio???

    Just change the line
    var ratio = "4:3";
    to
    var ratio = "3:2";

    All should then work.

  5. #5
    Junior Member
    Join Date
    Apr 2017
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Activity
    Points
    55
    Level
    2
    Lv. Percent
    57.67%

    Re: Automated aspect ratio???

    Thats what I would of thought and tried that but got this result, the 4x3 works perfectly

    Automated aspect ratio???-screen-shot-2017-04-20-16-40-39-png

  6. #6
    The Script Master
    Join Date
    May 2009
    Location
    Bradford,UK
    Posts
    325
    Post Thanks / Like
    Mentioned
    6 Post(s)
    Activity
    Points
    1,291
    Level
    12
    Lv. Percent
    25.08%
    Achievements Gaining PopularityQualified to FreelanceProfessional Poster
    Awards Scholar

    Re: Automated aspect ratio???

    The code is correct, it might be that you are not using a plain text editor?
    Some editors will add control characters that will stop the script working.

  7. #7
    Junior Member
    Join Date
    Apr 2017
    Posts
    5
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Activity
    Points
    55
    Level
    2
    Lv. Percent
    57.67%

    Re: Automated aspect ratio???

    Thanks Paul, spot on.

    I found a code editor called sublime txt, change the code using that and it worked beautifully.
    Thanks for taking the time to help me out, appreciate it.

    Scott

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About Photoshop Gurus
Photoshop Gurus (PSG) is a friendly community of designers and artists who enjoy all things related to Photoshop. PSG can consider itself one of the oldest Photoshop sites and has recently had it's 10th anniversary. We've come a long way and have every intention to continue supporting the Photoshop community. Photoshop can be an overwhelming program for beginners and that's how we try to help. We have a friendly forum, tutorials and all resources to help you understand this wonderful program. Feel free to look around and if you have any questions, don't hesitate to ask. Happy browsing!