How to get the greatest value of the width and/or height of two open images?

Re: Photoshop CS6, worm 13.0.1 (x 32) on Win 7 SP1 (64-bit) 16 GB of RAM

My Photoshop workflow processes repeatedly changing the games of two images of an irregularly shaped object, centered on a white background. After completing the changes, each canvas needs to be cropped, then the two resizing to square canvas of the same size.

The question I have is the last step: How can I determine the largest single dimension to use as the px width, height px square open two images?

The following script seems to work, but I don't know if I correctly selects active documents. Is app.activeDocument = app.documents [0] always the document being edited? And app.activeDocument = app.documents [1] no active document!

I am a programmer of VBA/VB.Net with no experience in Javascript. I'd greatly appreciate some expert opinions on what follows, my first attempt at a Photoshop script.

#target photoshop
< menu > automate < / menu >
Save the current configuration
var savedRuler = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.PIXELS;
whole white background
var backgroundC = new SolidColor();
backgroundC.rgb.red = 255;
backgroundC.rgb.green = 255;
backgroundC.rgb.blue = 255;
backgroundColor = backgroundC;
get the maximum size of the first image
app.activeDocument = app.documents [0] / / the value first image
var h = app.activeDocument.height;
var l = app.activeDocument.width;
var maxDim = w;
if(h>w) maxDim = h;
measure the second image and then get the two images max dimension
app.activeDocument = app.documents [1] / / for the second image
H2 var = app.activeDocument.height;
W2 var = app.activeDocument.width;
if(W2>maxDim) maxDim = w2;
if(H2>maxDim) maxDim = h2;
resize image second
app.activeDocument.resizeCanvas (maxDim, maxDim, AnchorPosition.MIDDLECENTER);
resize the image first
app.activeDocument = app.documents [0] / / the value first image
app.activeDocument.resizeCanvas (maxDim, maxDim, AnchorPosition.MIDDLECENTER);
clean
app.preferences.rulerUnits = savedRuler;

Try this

#target photoshop
//save the current setting
var savedRuler= app.preferences.rulerUnits;
var orig_display_dialogs = app.displayDialogs;
app.preferences.rulerUnits = Units.PIXELS;
app.displayDialogs = DialogModes.NO; // Set Dialogs off

var defaultFolder = "~";
var inputFolder = Folder.selectDialog("Choose a folder of images to process.", defaultFolder);
var outputFolder = Folder.selectDialog("Choose a folder to export resized images to.", defaultFolder);

var fileList = inputFolder.getFiles(/\.(nef|cr2|crw|dcs|raf|arw|orf|dng|jpg|jpe|jpeg|tif|tiff|psd|eps|png|bmp)$/i);
if (fileList.length%2===0) { // even number of files
  // Loop through files
  for (var i = 0; i < fileList.length; i++) {

     app.open(fileList[i]); // Open First
     app.activeDocument.trim(TrimType.TOPLEFT);
     app.activeDocument.resizeImage(null,null,1200,ResampleMethod.NONE);
     var h = app.activeDocument.height;
     var w = app.activeDocument.width;

     i++;
     app.open(fileList[i]); // open second
     app.activeDocument.trim(TrimType.TOPLEFT);
     app.activeDocument.resizeImage(null,null,1200,ResampleMethod.NONE);
     var h1 = app.activeDocument.height;
     var w1 = app.activeDocument.width;

     var maxDim = Math.max (Math.max (w, w1), Math.max (h, h1)) +10;

     app.activeDocument.resizeCanvas (maxDim, maxDim, AnchorPosition.MIDDLECENTER); //resize
     // save second and close
     if (app.activeDocument.name.lastIndexOf(".")!=0 ) { var Name = app.activeDocument.name.substring(0, app.activeDocument.name.lastIndexOf(".")); }
     else {var Name =  app.activeDocument.name;}
     var saveFile = outputFolder + "/" + Name ;
     SaveAsJPEG(saveFile, 10);
     activeDocument.close(SaveOptions.DONOTSAVECHANGES);     // Close the just save 

     app.activeDocument.resizeCanvas (maxDim, maxDim, AnchorPosition.MIDDLECENTER); //resize
     // save and close First
     if (app.activeDocument.name.lastIndexOf(".")!=0 ) { var Name = app.activeDocument.name.substring(0, app.activeDocument.name.lastIndexOf(".")); }
     else {var Name =  app.activeDocument.name;}
     var saveFile = outputFolder + "/" + Name ;
     SaveAsJPEG(saveFile, 10);
     activeDocument.close(SaveOptions.DONOTSAVECHANGES);     // Close the just save
     }
  }
else { alert("Odd Number of Files");}

//clean up
app.displayDialogs = orig_display_dialogs; // Reset display dialogs
app.preferences.rulerUnits = savedRuler;
////////////////////////////////////////////////////////////////////////////////////////////////////////

function SaveAsJPEG(saveFile, jpegQuality){
  var doc = activeDocument;
  if (doc.bitsPerChannel != BitsPerChannelType.EIGHT) doc.bitsPerChannel = BitsPerChannelType.EIGHT;
  jpgSaveOptions = new JPEGSaveOptions();
  jpgSaveOptions.embedColorProfile = true;
  jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
  jpgSaveOptions.matte = MatteType.NONE;
  jpgSaveOptions.quality = jpegQuality;
  activeDocument.saveAs(File(saveFile+".jpg"), jpgSaveOptions, true,Extension.LOWERCASE);
}

Tags: Photoshop

Similar Questions

  • How to get the width and height of Flex Mobile view?

    Hello

    The following instructions can get the width and height of the current Flex app:

    var request: UIComponent = FlexGlobals.topLevelApplication as UIComponent;

    trace (application. Width);

    trace (application. Height);

    But I don't know how to get the width and height of mobile display Flex current (i.e. the content size excludes bar action and the Navigation bar). Why the "this.width" always returns 0?

    Thank you!

    Looks like you're running in this bug: https://bugs.adobe.com/jira/browse/SDK-30070

  • How to get the width and height of a loaded image?

    Hello world

    Clicking on one of the 26 letters of the alphabet, I display 15 logos, starting with the first brand whose initial is the clicked letter.

    Logos have different dimensions, but I can't recover, so that they appear stretched or squeezed, retaining the width and the height of the first 15 logos put on stage in the edge source.

    Both the two console.log in the following code produces w = 0 h = 0 :

    -just after the assignment of the src attribute;

    -in the callback to the loadfunction.

    $('.letter').on ('click', Function)

    {

    swap the 15 images of logo

    for (var i = 0; i < 15; ++ I)

    {

    var patriciacartailler is sym. $("logo" + (i + 1));

    iBrand var = / / calculate the index of good

    radical var = .logo brands [iBrand];

    filePath var = ' images /' + radical + ".gif";

    var imLogo = new Image();

    imLogo.src = filePath;

    Console.log (I +' ' + radical +' BEFORE w = ' + imLogo.width +' h = ' + imLogo.height);

    patriciacartailler

    .Attr ('src', filePath)

    . Hide()

    . Load (Function)

    {

    Console.log (I +' ' + radical +' AFTER w = ' + imLogo.width +' h = ' + imLogo.height);

    $(this)

    .Attr ("width", imLogo.width)

    .Attr ("height", imLogo.height)

    . fadeIn();

    });

    }

    });

    Any idea? Thank you

    Gil

    Much better demesstified thank you, Zaxist.

    brands = {};

    Letter = {'A': 0, 'B': 0, 'C': 0,'d ': 0, 'E': 0, 'F': 0, 'G': 0, 'H': 0, 'I': 0, 'J': 0, 'K': 0, 'L': 0, ': 0,}

    {, 'O': 0, 'P': 0, 'Q': 0, 'R': 0, THE FROM ': 0, 'T': 0, 'U': 0, 'V': 0, 'W': 0, 'X': 0, 'Y': 0, 'Z': 0};

    //------------------------------------------------------

    $.getJSON ("brands.json", function (data))

    {

    the JSON file contains objects sorted by alphabetical order of their ownership of the mark

    brands = data;

    initialize the array of entries by letter

    key var = "z";

    $(données, fonction (index, entrée) .each)

    {

    initial var = entry.brand.charAt (0);

    If (initial! = key & initial! = 'É')

    {

    Letter [initial] = index;

    key = original;

    }

    });

    fill the empty entries

    for (var keyLetter in letter)

    {

    If (letter [keyLetter] == 0 & keyLetter! = 'A')

    {

    If (keyLetter is 'Z')

    {

    Letter ["Z"] = the letter ["Y"];

    } else {}

    value of the next entry

    [KeyLetter] = letter [string.fromCharCode(0)) (keyLetter.charCodeAt () + 1)];

    }

    }

    }

    swapLogos (0);

    });

    //------------------------------------------------------

    function swapLogos (iFirst)

    {

    Console.log (iFirst);

    for (var i = 0; i)< 15;="">

    {

    var patriciacartailler = sym.getSymbol ("cell_" + (i + 1)). $('square');

    iBrand var = iFirst + i;

    If (iBrand<>

    {

    patriciacartailler

    (. CSS

    {

    "background-image':" url (images / "+ .logo brands [iBrand] +".gif) ","

    'background-size': 'auto',

    'background-repeat': 'no-repeat '.

    'background-position': 'Center '.

    })

    . Show();

    } else {}

    theLogo.hide ();

    }

    }

    }

    //------------------------------------------------------

    $('.lettre').on ('click', Function)

    {

    var letter = $(this) .attr ('ID') .charAt (6).  Stage_A

    swapLogos (letter);

    update the letter highlighted (color)

    $('.lettre').css ('color', '#EEE');

    $(this) .css ('color', '#FF3');

    });

    //------------------------------------------------------

    Download here: https://app.box.com/s/c1hlvbfrum4yzypc1mid

    Gil

  • How to get the width and height of the model.

    Hi, I am writing a script which sends my AE comps in a render farm.  I need to retrieve the size of the frame (height and width) of the model.  But I'm unable to find the method to do it.  Is this possible via javascript?

    Thank you

    myComp would be a reference to your object model. You could get it from the activeItem if your comp is opened and selected:

    var app.project.activeItem = myComp;

    If not, you will need to loop through the elements of project until you find an element of the model with the name of the model you are looking for (not tested, but should be close):

    var myCompName = 'Hand Comp';

    var myComp = null;

    for (var i = 1; i)<= app.project.numitems;="">

    If ((.name app.project.item (i) == myCompName) & (app.project.item (i) instanceof CompItem)) {}

    myComp = app.project.item (i);

    }

    }

    If (myComp! = null) {}

    var l = myComp.width;

    var h = myComp.height;

    } else {}

    Alert ("Cannot find model" + myCompName);

    }

    Dan

  • How do I get the width and height of an external image

    Hello

    lets say I want to get the width and/or height of this external image (it could also be an external file on my hard drive): http://www.icatcher.com/wp-content/uploads/2013/01/Adobe.PNG

    I create a button and add an onClick function that says:

    var externalImageWidth = ???
    alert(externalImageWidth);
    

    How can I do (so to speak dynamically?)  without the addition of the image itself to my library or put it on the stage?

    All my attempts said 'indefinite' or '0' or they simply do not work.

    Thanks in advance!

    You can try the following (assuming that there is a dummy container with id mydiv = div),

    var img = new Image();

    IMG. OnLoad = function() {}

    SYM. $("mondiv") .attr ("width", this.width) .attr ("height", this.height) .append (this);

    };

    IMG. SRC = "http://www.icatcher.com/wp-content/uploads/2013/01/Adobe.png";

    Modify the code according to your need for the selection of the container element.

    DIA-

  • How to get the second and third weekend of every month over a period of time?

    Hello

    No idea how to get the second and third weekend of every month on a given period without use of CLAUSE?

    Thanks in advance.

    Try it below,

    SELECT CASE WHEN TO_CHAR (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'DY') = 'SAT '.

    THEN ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)) + 1

    WHERE TO_CHAR (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'DY') = 'Sun '.

    THEN ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)) + 6

    Of OTHER NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), "SAT") + 1

    END as second_weekendday,

    BOX WHEN TO_CHAR (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'DY') = 'SAT '.

    THEN ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)) + 7

    WHERE TO_CHAR (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'DY') = 'Sun '.

    THEN ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)) + 7

    Of OTHER NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), "SAT") + 7

    END AS third_weekendday

    FROM (SELECT SYSDATE startdate,

    SYSDATE + 300 enddate

    THE DOUBLE)

    CONNECT BY LEVEL<=>

  • Get the width and height of the image

    Hi scripters

    I try to get the width and height of my image file. Here is my code

    myPicFile = File("c:\\ar.eps");

    h = myPicFile.height;

    w = myPicFile.width;

    Alert (h)

    Copy the following code generates error

    ---------------------------
    Script alert
    ---------------------------
    undefined
    ---------------------------
    Ok
    ---------------------------

    How can I get the height and the width of my image? is there another method?

    Thanks in advance

    concerning

    a you are the

    Dear Arul,

    Here, my code is in InDesign. I don't know that we get the size of the Image directly. ?

    Throught InDesign [you using the InDesign Script then] Script here I pasted the code below...

    = Image height / width =.

    myDoc var = app.activeDocument;

    myPicFile = file ("E:\\HariharaSudhan\\Blue hills.jpg");

    App.place (file (myPicFile);

    = Then u please select the Image file in InDesign and then you run the script = / /.

    mySel var = app.selection [0];

    var limit = mySel.geometricBounds;

    var height = related [2] - bound [0];
    var width = Bound [3] - bound [1];

    Alert ("Image Height:" + height + ""+"Image width:" + width);

    = End: getting the Image height / width =.

    Please let me know if you have any questions.

    Thank you & best regards

    Thierry T.R.Harihara

  • How to get the number and the name of the contacts selector

    Hi all

    I got the Contact Picker work but I have no idea how to get the selected telephone number and the name.

    There are attributes that I can put like contactId.value () to retrieve or there is another way?

    Thanks in advance.

    ImageButton{
                        defaultImageSource: "asset:///images/bluebutton.png"
                        onClicked: {
                            contactPicker.open();
                        }
                        attachedObjects: [
                            ContactPicker {
                                id: contactPicker
                                onContactSelected: {
                                    result.text = "You chose contact: " + contactId;
                                }
                            }
                        ]
    
                    }
    
                    Label {
                        id: result
                        text: "You chose contact: "
                    }
    

    Hello

    You can get the contact name and phone number as this,

    ImageButton{
                        defaultImageSource: "asset:///images/bluebutton.png"
                        onClicked: {
                            contactPicker.open();
                        }
                        attachedObjects: [
                            ContactPicker {
                                id: contactPicker
                                onContactSelected: {
                                    result.text = "You chose contact: " + contactId;
    // call a cpp method to get the details
    
    app.getDetails(contactId); } } ] } Label { id: result text: "You chose contact: " }
    

    the CPP code:

    void ContactDetails(ContactId id)
    {
    Contact contact_info = m_contactService->contactDetails(id);
    
        QString firstName = contact_info.firstName();
        QString lastname = contact_info.lastName();
            QList phoneno_list = contact_info.phoneNumbers();
    
        QStringList no_s;
    
        foreach(ContactAttribute attr, phoneno_list)
        {
            no_s << attr.value();
        }
    }
    

    You can get details like this.

    Kind regards

    Naresh Kodumuri.

  • How to get the name and number of the procedure parameter list or a function?

    I stated the procedure described in the package

    If I want to get the number and the name of the parameter list, so how do I it

    I don't have I her name with the package.

    create or replace package demoApp is

    PROCEDURE insert_data (p_fname IN VARCHAR2,

    p_lname IN VARCHAR2,

    p_address IN VARCHAR2,

    p_cellno IN VARCHAR2,

    p_email IN varchar2);

    end demoApp;

    create or replace package demoApp body is

    PROCEDURE insert_data (p_fname IN VARCHAR2,

    p_lname IN VARCHAR2,

    p_address IN VARCHAR2,

    p_cellno IN VARCHAR2,

    p_email IN varchar2) IS

    EmpID number;

    BEGIN

    Select nvl (max (emp1.empid), 0) + 1 in EMP1 empid;

    INSERT INTO VALUES EMP1 (empid, p_fname, p_lname, p_address, p_cellno, p_email);

    EXCEPTION

    WHILE OTHERS THEN

    raise_application_error (-20001,' insert the problem ' |) SQLERRM);

    END;

    end demoApp;

    -----------------

    I want to get the name of the parameter and the number of use of stroredrprocedure ""demoApp.insert_data " "

    Select *.

    of all_arguments

    where package_name = 'DEMOAPP.

    and object_name = 'INSERT_DATA.

  • How to get the coordinates and the size of the swf to scale components

    I use the Web (I put it to the size of the entire screen) to frame a swfloader that loads a swf file with the width and height set to 100%. This swf has a movieclip. How can I get the exact coordinates of his position and its size after the scaling in Flex?

    In Flash CS4, the movielip a x = 40, y = 700. In Flex, the swf file is set to 100% scale, but when I get the x value of this movieclip, it is always 40. I try to get the scale of the x axis ratio using scaleX of swf. But his 1, pretty weird.

    How can I get the correct coordinates of the movieclip?

    The coordinates are usually compared to something.  X is relative to the parent.

    LocalToGlobal and globalToLocal convert coordinated areas.

    You can go to transform.pixelBounds and

    transform.concatenatedMatrix.

  • How to get the length and sub lymph nodes.

    Hello

    find the script below.

    < List1 >

    < list >

    < List1 >

    < List1 >

    < List1 >

    < / list >

    < list >

    < List2 >

    < List2 >

    < List2 >

    < / list >

    --

    --

    -

    -

    -

    -< / list1 >

    Here the tag list will be growing based on the I / p. Now what I want is to know how to get the length of the tag < list >.

    To implement the above I used the code below

    var number = xfa.record.List1.List [0].nodes.length; (Does not work)

    But if var account = xfa.record.List1.nodes.length; (work)

    and also I want to delete a tag inside the < List > tag. How?

    Very Urgent.

    Thanks in advance.

    Yes, you need to use the name instead of the value to get the tag name...

    xfa.datsets.data.Root.nodes.item (0) .name

    Thank you

    Srini

  • How to get the phone and messages back in my dock apps? And for some reason, I discover now all my app pages from the middle of my phone and not at the top?

    How can I get the phone and messages apps in my dock? And for some reason, I discover now all my app pages from the middle of my phone and not at the top?

    Try

    Settings > general > reset > reset home screen presentation.

    Note: All other applications will be organised by alphabetical order.

  • How to get the scanning and fax utilities works from 2840 printer. Print function works from pc

    I changed my google chrome browser and I finally got my confiquered pc and printer. He is an all-in-one 2840 color laser jet. How do I get the scan and fax utilities to perform?

    It is useful to include the manufacturer and model number.

    What version of Windows you have, including the service pack?

    How the device is connected to your computer (USB, Ethernet, other)?

    Have you installed the software that came with your HP Color LaserJet 2840 AiO printer?

    If not, why?  If you did, what error messages you are seeing?  Please report messages completely, without paraphrasing.

    Start here: HP Color LaserJet 2820 and 2840 AiO products Series - first installation and install

  • How to get the LOGO and company name in the theme of the 4 apex

    Hello

    I use the theme 4 for apex 4.0.2.
    I must have the logo as well as the name of the company the two, but when I select den Image it shows only the image in the dashboard and when I select den text it shows the name of the company.
    How to get the two logo and the name of the company?

    Thanks for your help.

    Kind regards
    Sébastien Pallav.

    Pushpesh Pallav says:
    Hello

    I use the theme 4 for apex 4.0.2.
    I must have the logo as well as the name of the company the two, but when I select den Image it shows only the image in the dashboard and when I select den text it shows the name of the company.

    The word is spelled 'then', not 'den '.

    How to get the two logo and the name of the company?

    Select the text, and include HTML, making reference to the image in the text:

    
    

    The image src URI used depends on the location of the image, which you have failed to specify.

  • How to get the public and private keys to use recaptcha?

    I registered with google to get a recaptcha for my Web site. I've gotten has been the key to site and the secret key! If I need to get the public and private key for muse!

    Hello

    Please use the site as a 'public key'key key and Secret as "clΘ privΘe".

    Concerning

    Vivek

Maybe you are looking for