Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Random crop batch processing script

Community Beginner ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

Hi there! I have a lot widescreen panoramic (horizontal) images, and i need to square crop them at the random places (center, left border, right border, and the same with some rotation) with saving each croped image with specific name (file name + 01, 02, 03 etc) Very need script with the specified functions that can do it in batch mode with opening some folder with files and saving ready images in to the another folder. I'm very new in the scripting and for me it is very hard, i even dont imagine how it is must be to look like. As i know Photoshop cant't align the square crop frame (1:1)

Please somebody help me if it posible.

TOPICS
Actions and scripting

Views

1.2K

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Adobe Community Professional , Aug 15, 2018 Aug 15, 2018
OK. This is a bug. Check the new version. if (app.documents.length) main();function main()    {    app.displayDialogs = DialogModes.NO;    app.preferences.rulerUnits = Units.CM;    var jpg_options = new JPEGSaveOptions();    with (jpg_options)        {        embedColorProfile = true;        matte             = MatteType.WHITE;        formatOptions     = FormatOptions.STANDARDBASELINE;        scans             = 3;        quality           = 10;        }    var doc = activeDocument;    var doc_...

Likes

Translate

Translate
Adobe Community Professional ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

Make a Square Selection anywhere you want crop save the revert to before the crop and repeat this  for the other crops you want.

JJMack

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

Create a script. Open your document.

Run the script. A folder named CROPS appears next to the file on the disk. It will have your new files.

To change the type of crops, change or remove\add crop_and_save() lines to the script.

For example, string

crop_and_save("C", -10);

means crop in the center and rotate to minus 10 degrees.

After setting up the algorithm, close all the documents, create a new Action in the Actions panel and record the call to the script.

Run Batch with this Action, with the destination "None", for your folder with the files.

I think you understood my English. ))

if (app.documents.length) main();

function main()

    {

    app.displayDialogs = DialogModes.NO;

    app.preferences.rulerUnits = Units.CM;

    var jpg_options = new JPEGSaveOptions();

    with (jpg_options)

        {

        embedColorProfile = true;

        matte             = MatteType.WHITE;

        formatOptions     = FormatOptions.STANDARDBASELINE;

        scans             = 3;

        quality           = 10;

        }

    var doc = activeDocument;

    var doc_name = doc.name;

    var n = doc_name.lastIndexOf(".");

    if (n > 0) doc_name = doc_name.substr(0, n);

    var doc_path = new Folder(doc.path.fsName + "/" + "CROPS")

    if (!doc_path.exists) doc_path.create();

    /// HERE ARE YOUR CROPS ////////////////////////////////////////////////

    crop_and_save("L", 0);   // left crop

    crop_and_save("C", 0);   // center crop

    crop_and_save("R", 0);   // right crop

    crop_and_save("L", -10); // left crop angle = -10

    crop_and_save("C", -10); // center crop angle = -10

    crop_and_save("R", -10); // right crop angle = -10

    crop_and_save("L", 20);  // left crop angle = +20 

    crop_and_save("C", 20);  // center crop angle = +20

    crop_and_save("R", 20);  // right crop angle = +20

    //////////////////////////////////////////////////////////////////////

    doc.close(SaveOptions.DONOTSAVECHANGES);

    return;

    //////////////////////////////////////////////////////////////////////

    function crop_and_save(pos, a)

        {

        var w = Number(doc.width.value);

        var h = Number(doc.height.value);

        var y0 = 0;

        var y1 = h;

        var x0;

        var x1;

        if (pos == "L")

            {

            x0 = 0;

            x1 = h;

            }

        else if (pos == "C")

            {

            x0 = w/2 - h/2;

            x1 = w/2 + h/2;

            }

        else if (pos == "R")

            {

            x0 = w-h;

            x1 = w;

            }

        else

            {

            throw("Bad position");

            return;

            }

   

        var size = h/(Math.sin(Math.abs(a)*Math.PI/180) + Math.cos(Math.abs(a)*Math.PI/180));

   

        if (!crop_action(x0+(h-size)/2,y0+(h-size)/2, x0+(h-size)/2+size,y0+(h-size)/2+size, a)) return;

   

        if (a > 0)

            doc.saveAs(File(doc_path.fsName + "/" + doc_name + "_"+ pos + "+" + a.toString()), jpg_options);

        else if (a < 0)

            doc.saveAs(File(doc_path.fsName + "/" + doc_name + "_"+ pos + a.toString()), jpg_options);

        else

            doc.saveAs(File(doc_path.fsName + "/" + doc_name + "_"+ pos), jpg_options);

   

        var d = new ActionDescriptor();

        var r = new ActionReference();

        r.putIndex( charIDToTypeID( "SnpS" ), 1);

        d.putReference( charIDToTypeID( "null" ), r );

        executeAction( charIDToTypeID( "slct" ), d, DialogModes.NO );

        }

    }

////////////////////////////////////////////////////////////////////////////////////////////

function crop_action(x0,y0, x1,y1, a)

    {

    try {

        x0 = x0 *72/2.54;

        x1 = x1 *72/2.54;

        y0 = y0 *72/2.54;

        y1 = y1 *72/2.54;

        var d = new ActionDescriptor();

        var d1 = new ActionDescriptor();

        d1.putUnitDouble( charIDToTypeID( "Top " ), charIDToTypeID( "#Rlt" ), y0 );

        d1.putUnitDouble( charIDToTypeID( "Left" ), charIDToTypeID( "#Rlt" ), x0 );

        d1.putUnitDouble( charIDToTypeID( "Btom" ), charIDToTypeID( "#Rlt" ), y1 );

        d1.putUnitDouble( charIDToTypeID( "Rght" ), charIDToTypeID( "#Rlt" ), x1 );

        d.putObject( charIDToTypeID( "T   " ), charIDToTypeID( "Rctn" ), d1 );

        d.putUnitDouble( charIDToTypeID( "Angl" ), charIDToTypeID( "#Ang" ), a );

        d.putBoolean( charIDToTypeID( "Hd  " ), false );

        executeAction( charIDToTypeID( "Crop" ), d, DialogModes.NO );

        return true;

        }

    catch (e) { alert(e); return false; }

    }

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

Your English is great as your scripting! ) But i think i do something wrong, for try and clear understood, i change in line 32 crop_and_save("C", 0);   // center crop

to

crop_and_save("C", -180);   // center crop angle = -180

And nothing changes. What i do wrong?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

OK. This is a bug. Check the new version.

if (app.documents.length) main();

function main()

    {

    app.displayDialogs = DialogModes.NO;

    app.preferences.rulerUnits = Units.CM;

    var jpg_options = new JPEGSaveOptions();

    with (jpg_options)

        {

        embedColorProfile = true;

        matte             = MatteType.WHITE;

        formatOptions     = FormatOptions.STANDARDBASELINE;

        scans             = 3;

        quality           = 10;

        }

    var doc = activeDocument;

    var doc_name = doc.name;

    var n = doc_name.lastIndexOf(".");

    if (n > 0) doc_name = doc_name.substr(0, n);

    var doc_path = new Folder(doc.path.fsName + "/" + "CROPS")

    if (!doc_path.exists) doc_path.create();

    /// HERE ARE YOUR CROPS ////////////////////////////////////////////////

    crop_and_save("C",  -180);  

    crop_and_save("C", 0);  

    crop_and_save("R", 0);  

 

    crop_and_save("L", -10);

    crop_and_save("C", -10);

    crop_and_save("R", -10);

    crop_and_save("L", 20); 

    crop_and_save("C", 20); 

    crop_and_save("R", 20); 

 

    //////////////////////////////////////////////////////////////////////

    doc.close(SaveOptions.DONOTSAVECHANGES);

    return;

    //////////////////////////////////////////////////////////////////////

    function crop_and_save(pos, a)

        {

        var w = Number(doc.width.value);

        var h = Number(doc.height.value);

        var y0 = 0;

        var y1 = h;

        var x0;

        var x1;

        if (pos == "L")

            {

            x0 = 0;

            x1 = h;

            }

        else if (pos == "C")

            {

            x0 = w/2 - h/2;

            x1 = w/2 + h/2;

            }

        else if (pos == "R")

            {

            x0 = w-h;

            x1 = w;

            }

        else

            {

            throw("Bad position");

            return;

            }

 

        var a1 = a

        if (a1 > 180)  a1 = 360-a1;

        if (a1 < -180) a1 = 360+a1;

        if (a1 < 0)    a1 = 180+a1;

        if (a1 > 90)   a1 = 180-a1;

        a1 = Math.abs(a1)*Math.PI/180

        var size = Math.abs(h/(Math.sin(a1) + Math.cos(a1)));

        if (!crop_action(x0+(h-size)/2,y0+(h-size)/2, x0+(h-size)/2+size,y0+(h-size)/2+size, a)) return;

        if (a > 0)

            doc.saveAs(File(doc_path.fsName + "/" + doc_name + "_"+ pos + "+" + a.toString()), jpg_options);

        else if (a < 0)

            doc.saveAs(File(doc_path.fsName + "/" + doc_name + "_"+ pos + a.toString()), jpg_options);

        else

            doc.saveAs(File(doc_path.fsName + "/" + doc_name + "_"+ pos), jpg_options);

   

        var d = new ActionDescriptor();

        var r = new ActionReference();

        r.putIndex(stringIDToTypeID( "snapshotClass" ), 1);

        d.putReference(stringIDToTypeID("null"), r);

        executeAction(stringIDToTypeID("select"), d, DialogModes.NO);

        }

    }

////////////////////////////////////////////////////////////////////////////////////////////

function crop_action(x0,y0, x1,y1, a)

    {

    try {

        x0 = x0 *72/2.54;

        x1 = x1 *72/2.54;

        y0 = y0 *72/2.54;

        y1 = y1 *72/2.54;

        var d = new ActionDescriptor();

        var d1 = new ActionDescriptor();

        d1.putUnitDouble(stringIDToTypeID("top"),    stringIDToTypeID("distanceUnit"), y0);

        d1.putUnitDouble(stringIDToTypeID("left"),   stringIDToTypeID("distanceUnit"), x0);

        d1.putUnitDouble(stringIDToTypeID("bottom"), stringIDToTypeID("distanceUnit"), y1);

        d1.putUnitDouble(stringIDToTypeID("right"),  stringIDToTypeID("distanceUnit"), x1);

        d.putObject(stringIDToTypeID("to"), stringIDToTypeID("rectangle"), d1);

        d.putUnitDouble(stringIDToTypeID("angle"), stringIDToTypeID("angleUnit"), a);

        d.putBoolean(stringIDToTypeID("delete"), true);

        executeAction(stringIDToTypeID("crop"), d, DialogModes.NO);

        return true;

        }

    catch (e) { alert(e); return false; }

    }

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 15, 2018 Aug 15, 2018

Copy link to clipboard

Copied

What particular rotations are you interested in?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 16, 2018 Aug 16, 2018

Copy link to clipboard

Copied

Kukurykus  написал(а)

What particular rotations are you interested in?

On the random batch random angle from 5-7 up to 180 degree

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

Benjaminlion 

Kukurykus 

What particular rotations are you interested in?

On the random batch random angle from 5-7 up to 180 degree

This can be useful

crop_and_save(rand_pos(), rand_angle());    

crop_and_save(rand_pos(), rand_angle());    

crop_and_save(rand_pos(), rand_angle());    

crop_and_save(rand_pos(), rand_angle());    

crop_and_save(rand_pos(), rand_angle());    

crop_and_save(rand_pos(), rand_angle());    

crop_and_save(rand_pos(), rand_angle());    

crop_and_save(rand_pos(), rand_angle());    

crop_and_save(rand_pos(), rand_angle());    

crop_and_save(rand_pos(), rand_angle());    

crop_and_save(rand_pos(), rand_angle());    

crop_and_save(rand_pos(), rand_angle());    

function rand_pos()

    {

    var x = Math.random();

    if (x < 1/3) return "L";

    if (x < 2/3) return "C";

    return "R";

    }

function rand_angle(min, max)

    {

    if (min == undefined) min = 5;

    if (max == undefined) max = 180;

    return Math.round((min+(max-min)*Math.random()) * (Math.random()<0.5?1:-1));

    }

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

Is this is full script or just fragment? I try to use it ind have error on line1 (crop_and_save is not a function)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

This is part of the code. Insert it instead of the old lines with crop_and_save(...);
The number of calls with crop_and_save() in the new code is set by yourself.
In the example above there are 12 calls.

upd.

Full code

if (app.documents.length) main(); 

 

function main() 

    { 

    app.displayDialogs = DialogModes.NO; 

 

    app.preferences.rulerUnits = Units.CM; 

 

    var jpg_options = new JPEGSaveOptions(); 

 

    with (jpg_options) 

        { 

        embedColorProfile = true; 

        matte             = MatteType.WHITE; 

        formatOptions     = FormatOptions.STANDARDBASELINE; 

        scans             = 3; 

        quality           = 10; 

        } 

 

    var doc = activeDocument; 

 

    var doc_name = doc.name; 

    var n = doc_name.lastIndexOf("."); 

    if (n > 0) doc_name = doc_name.substr(0, n); 

 

    var doc_path = new Folder(doc.path.fsName + "/" + "CROPS") 

    if (!doc_path.exists) doc_path.create(); 

 

    /// HERE ARE YOUR CROPS //////////////////////////////////////////////// 

    crop_and_save(rand_pos(), rand_angle());    

    crop_and_save(rand_pos(), rand_angle());    

    crop_and_save(rand_pos(), rand_angle());    

    crop_and_save(rand_pos(), rand_angle());    

    crop_and_save(rand_pos(), rand_angle());    

    crop_and_save(rand_pos(), rand_angle());    

    crop_and_save(rand_pos(), rand_angle());    

    crop_and_save(rand_pos(), rand_angle());    

    crop_and_save(rand_pos(), rand_angle());    

    crop_and_save(rand_pos(), rand_angle());    

    crop_and_save(rand_pos(), rand_angle());    

    crop_and_save(rand_pos(), rand_angle());    

    function rand_pos()

        {

        var x = Math.random();

        if (x < 1/3) return "L";

        if (x < 2/3) return "C";

        return "R";

        }

    function rand_angle(min, max)

        {

        if (min == undefined) min = 5;

        if (max == undefined) max = 180;

        return Math.round((min+(max-min)*Math.random()) * (Math.random()<0.5?1:-1));

        }

   

    ////////////////////////////////////////////////////////////////////// 

 

    doc.close(SaveOptions.DONOTSAVECHANGES); 

    return; 

 

    ////////////////////////////////////////////////////////////////////// 

    function crop_and_save(pos, a) 

        { 

        var w = Number(doc.width.value); 

        var h = Number(doc.height.value); 

 

        var y0 = 0; 

        var y1 = h; 

 

        var x0; 

        var x1; 

 

        if (pos == "L") 

            { 

            x0 = 0; 

            x1 = h; 

            } 

        else if (pos == "C") 

            { 

            x0 = w/2 - h/2; 

            x1 = w/2 + h/2; 

            } 

 

        else if (pos == "R") 

            { 

            x0 = w-h; 

            x1 = w; 

            } 

        else 

            {  

            throw("Bad position"); 

            return; 

            } 

   

        var a1 = a 

 

        if (a1 > 180)  a1 = 360-a1; 

        if (a1 < -180) a1 = 360+a1; 

        if (a1 < 0)    a1 = 180+a1; 

        if (a1 > 90)   a1 = 180-a1; 

 

        a1 = Math.abs(a1)*Math.PI/180 

 

        var size = Math.abs(h/(Math.sin(a1) + Math.cos(a1))); 

 

        if (!crop_action(x0+(h-size)/2,y0+(h-size)/2, x0+(h-size)/2+size,y0+(h-size)/2+size, a)) return; 

 

        if (a > 0) 

            doc.saveAs(File(doc_path.fsName + "/" + doc_name + "_"+ pos + "+" + a.toString()), jpg_options); 

        else if (a < 0) 

            doc.saveAs(File(doc_path.fsName + "/" + doc_name + "_"+ pos + a.toString()), jpg_options); 

        else 

            doc.saveAs(File(doc_path.fsName + "/" + doc_name + "_"+ pos), jpg_options); 

     

        var d = new ActionDescriptor(); 

        var r = new ActionReference(); 

        r.putIndex(stringIDToTypeID( "snapshotClass" ), 1); 

        d.putReference(stringIDToTypeID("null"), r); 

        executeAction(stringIDToTypeID("select"), d, DialogModes.NO); 

        } 

    } 

 

//////////////////////////////////////////////////////////////////////////////////////////// 

function crop_action(x0,y0, x1,y1, a) 

    { 

    try { 

        x0 = x0 *72/2.54; 

        x1 = x1 *72/2.54; 

        y0 = y0 *72/2.54; 

        y1 = y1 *72/2.54; 

 

        var d = new ActionDescriptor(); 

        var d1 = new ActionDescriptor(); 

        d1.putUnitDouble(stringIDToTypeID("top"),    stringIDToTypeID("distanceUnit"), y0); 

        d1.putUnitDouble(stringIDToTypeID("left"),   stringIDToTypeID("distanceUnit"), x0); 

        d1.putUnitDouble(stringIDToTypeID("bottom"), stringIDToTypeID("distanceUnit"), y1); 

        d1.putUnitDouble(stringIDToTypeID("right"),  stringIDToTypeID("distanceUnit"), x1); 

        d.putObject(stringIDToTypeID("to"), stringIDToTypeID("rectangle"), d1); 

        d.putUnitDouble(stringIDToTypeID("angle"), stringIDToTypeID("angleUnit"), a); 

        d.putBoolean(stringIDToTypeID("delete"), true); 

        executeAction(stringIDToTypeID("crop"), d, DialogModes.NO); 

        return true; 

        } 

    catch (e) { alert(e); return false; } 

    }

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

Thanks for all. You are the master of code 😃 I try random version - it work great! Some time i need to control angle (strict +90, -90, 180), some time good be random version. Thanks again, you save my eyes ))

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Aug 17, 2018 Aug 17, 2018

Copy link to clipboard

Copied

Is that Sometimes also random?

   /// HERE ARE YOUR CROPS ////////////////////////////////////////////////  

   if (Math.random() < 1/2) {

     crop_and_save("C", 90);   

     crop_and_save("C", -90); 

     crop_and_save("C", 180);   

   }

   else {

      x = Math.floor(Math.random() * 10) +1

      for (i = 0; i < x; i++) {

         crop_and_save(rand_pos(), rand_angle());     

         }

   }

JJMack

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

Hi and thank you in advance...

 

I found the following script in Random crop batch processing script trhead and I need to modify it but I have no idea where to start...

What I am trying to do is to select a folder with high resolution images and have the script create square crops from that image and save them with the same (file_name -1 -2 -3).jpg

The crop location should be random each time.

 

It would be best if the script can set the crop size as a percentage of the original file then save the result as a 1000x1000 px image.

Aug 17, 2018

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

Thanks but if I could do it myself I wouldn't be asking...

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

That is why I post the document you start by learning  Photoshop  scripting.

JJMack

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

In this case you should close this forum and just link to this PDF 

 

I see you are posting and modifying codes for other requests and not pasting this PDF, any reason why? Or do you have a personal problem with me for some reason?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 22, 2021 Oct 22, 2021

Copy link to clipboard

Copied

I do not have a problem  posting this that pdf in other threads and I have. I have also posted Javascript suggestions to the bst of my knowledge in other thread. I only hack at Photoshop scripting I doe not actually know much about javascript. These forums are Design for helping other user like myself out.  I have been help out here many time myself with problems I don't know how to code for I lack knowledge about Action Manager coding.   I  sometimes ask for help because of that.  Most of the time I just search for solutions for for my problems because the are my problems.  I do have a problem with users like yourself that ask for other to work for you because you do want to learn  how to do your work,  You want other to work for you without any compensation. That rubs me the wrong way.  If you want to use Photoshop automation you should learn how to use it. Just like you learn to use other features in Photoshop. Study the PDF.

JJMack

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 23, 2021 Oct 23, 2021

Copy link to clipboard

Copied

"These forums are Design for helping other user like myself out."

So all people here are just to help YOU but no one else?

Why don't YOU read the PDF then and not ask anyone for help?

 

These forums are designed for people to help others not to bully them, if you are unwilling to help then don't force your opinions and crappy feelings on my request. Also this is not Fiverr, the last I checked these are free online forums made by the company selling the software to make it easier for its customers to make the best of its software.

 

I did not ask for someone to work for me, I did my own research and looked through hundreds of posts and websites to find a very similar code to what I need which just needs a change in a couple of lines that someone who knows scripting and is willing to help would take him 5 minutes to modify rather than for me to learn a whole new programming language that would take me weeks to figure out.

 

The way I see it you are willing to help others freely but you stormed here to bully me and prevent others from helping me, yet you know nothing about me expet my name, which clearly you have an issue with and this says a lot about YOU.

 

 

P.S. here is some help you clearly need HomeLearnEnglish

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 23, 2021 Oct 23, 2021

Copy link to clipboard

Copied

Expand you research read the PDF.  I'm not bullying you I'm trying to help you learn about scripting Photoshop to automate the processing you want to do.  You have ask other to work for you and provides some design features  they should do for you. You have not ask  how to go about modifying the script here.  To work the way to want.  Read the script code the File Names it saves is simple to changes.  It is also easy to add a Image resize  to 1000x1000 for and 1:1 aspect ratio crop. based on some percentage you never specified of the original image.  Image resize will resample the cropped  image up or down to the 1000x1000 image you want.

JJMack

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 23, 2021 Oct 23, 2021

Copy link to clipboard

Copied

Maybe you were bad boy this year and the 'santa' isn't going to bring the gift for you 😛

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Oct 23, 2021 Oct 23, 2021

Copy link to clipboard

Copied

 

#target photoshop;

randomSquareCropAndSave(10, 1000)

function randomSquareCropAndSave(coveragePercent, size) {
    try {
        try {
            var doc = new AM(p = 'document'),
                docRes = doc.getProperty(p = 'resolution'),
                docWidth = doc.getProperty(p = 'width') / 72 * docRes,
                docHeight = doc.getProperty(p = 'height') / 72 * docRes,
                docPath = doc.getProperty(p = 'fileReference'),
                quardSide = parseInt(Math.sqrt((coveragePercent / 100) * docWidth * docHeight) / 2);
        } catch (e) { throw ('Document property "' + p + '" not found!\n\n' + e) }

        if (quardSide * 2 > docWidth || quardSide * 2 > docHeight) throw ('Cropping area is larger than the document area!')

        var centerX = parseInt((quardSide + Math.random() * (docWidth - quardSide * 2))),
            centerY = parseInt((quardSide + Math.random() * (docHeight - quardSide * 2)));

        doc.makeNewCopy()

        doc.crop(centerY - quardSide, centerX - quardSide, centerY + quardSide, centerX + quardSide, size, size, docRes)
        doc.saveAsJpg(function (fle, ext) {
            var uniqueFileName = fle + ext,
                fileNumber = 1;
            while (File(uniqueFileName).exists) {
                uniqueFileName = fle + "-" + fileNumber + ext;
                fileNumber++;
            }
            return File(uniqueFileName);
        }(decodeURI(docPath.path) + '/' + decodeURI(docPath.name).replace(/\..+$/, ''), '.jpg'), 12);
        doc.close();
    } catch (e) { alert(e) }
}

function AM(target) {
    var s2t = stringIDToTypeID,
        t2s = typeIDToStringID;

    target = target ? s2t(target) : null;

    this.getProperty = function (property, id, idxMode) {
        property = s2t(property);
        (r = new ActionReference()).putProperty(s2t('property'), property);
        id != undefined ? (idxMode ? r.putIndex(target, id) : r.putIdentifier(target, id)) :
            r.putEnumerated(target, s2t('ordinal'), s2t('targetEnum'));
        return getDescValue(executeActionGet(r), property)
    }

    this.hasProperty = function (property, id, idxMode) {
        property = s2t(property);
        (r = new ActionReference()).putProperty(s2t('property'), property);
        id ? (idxMode ? r.putIndex(target, id) : r.putIdentifier(target, id))
            : r.putEnumerated(target, s2t('ordinal'), s2t('targetEnum'));
        return executeActionGet(r).hasKey(property)
    }

    this.makeNewCopy = function () {
        (r = new ActionReference()).putClass(s2t('document'));
        (d = new ActionDescriptor()).putReference(s2t('target'), r);
        (r1 = new ActionReference()).putProperty(s2t('historyState'), s2t('currentHistoryState'));
        d.putReference(s2t('using'), r1);
        executeAction(s2t('make'), d, DialogModes.NO);
    }

    this.crop = function (top, left, bottom, right, width, height, resolution) {
        (d = new ActionDescriptor()).putUnitDouble(s2t('top'), s2t('pixelsUnit'), top);
        d.putUnitDouble(s2t('left'), s2t('pixelsUnit'), left);
        d.putUnitDouble(s2t('bottom'), s2t('pixelsUnit'), bottom);
        d.putUnitDouble(s2t('right'), s2t('pixelsUnit'), right);
        (d1 = new ActionDescriptor()).putObject(s2t('to'), s2t('rectangle'), d);
        d1.putUnitDouble(s2t("angle"), s2t("angleUnit"), 0);
        d1.putBoolean(s2t('delete'), true);
        d1.putEnumerated(s2t('cropAspectRatioModeKey'), s2t('cropAspectRatioModeClass'), s2t('targetSize'));
        d1.putUnitDouble(s2t('width'), s2t('pixelsUnit'), width);
        d1.putUnitDouble(s2t('height'), s2t('pixelsUnit'), height);
        d1.putUnitDouble(s2t('resolution'), s2t('densityUnit'), resolution);
        executeAction(s2t('crop'), d1, DialogModes.NO);
    }

    this.saveAsJpg = function (pth, quality) {
        (d = new ActionDescriptor()).putInteger(s2t('extendedQuality'), quality);
        d.putEnumerated(s2t('matteColor'), s2t('matteColor'), s2t('none'));
        (d1 = new ActionDescriptor()).putObject(s2t('as'), s2t('JPEG'), d);
        d1.putPath(s2t('in'), pth);
        executeAction(s2t('save'), d1, DialogModes.NO);
    }

    this.close = function () {
        (d = new ActionDescriptor()).putEnumerated(s2t('save'), s2t('yesNo'), s2t('no'));
        executeAction(s2t('close'), d, DialogModes.NO)
    }

    function getDescValue(d, p) {
        switch (d.getType(p)) {
            case DescValueType.OBJECTTYPE: return { type: t2s(d.getObjectType(p)), value: d.getObjectValue(p) };
            case DescValueType.LISTTYPE: return d.getList(p);
            case DescValueType.REFERENCETYPE: return d.getReference(p);
            case DescValueType.BOOLEANTYPE: return d.getBoolean(p);
            case DescValueType.STRINGTYPE: return d.getString(p);
            case DescValueType.INTEGERTYPE: return d.getInteger(p);
            case DescValueType.LARGEINTEGERTYPE: return d.getLargeInteger(p);
            case DescValueType.DOUBLETYPE: return d.getDouble(p);
            case DescValueType.ALIASTYPE: return d.getPath(p);
            case DescValueType.CLASSTYPE: return d.getClass(p);
            case DescValueType.UNITDOUBLE: return (d.getUnitDoubleValue(p));
            case DescValueType.ENUMERATEDTYPE: return { type: t2s(d.getEnumerationType(p)), value: t2s(d.getEnumerationValue(p)) };
            default: break;
        };
    }
}

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Oct 24, 2021 Oct 24, 2021

Copy link to clipboard

Copied

LATEST

WOW!!

That's way more than a couple of lines!

 

Thank you and your beautiful soul. It worked great!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines