Photoshop Automation: Place Logo in corner of image which has the most ’empty space’

I would like to automate the following process: place a logo on a large number of images I have. The logo should be placed in one of the four corners of the image (bottom left, top left, bottom right or top right corner). If possible in the corner which can fit the biggest size logo.

Here is an example image:

Trailer example
Click here for full size

I have placed a logo in each corner of the image and scaled each logo such that the logo makes contact with the base image (a trailer in this example image).

In the case of this image the logo should be placed in the Top Right corner (as this will result in the biggest size logo).

I have thought of a method of how I would like to approach this problem (determining where the logo should be placed). Although I am not sure if this or a similar method is possible in Photoshop. (the steps displayed in the image below are manual steps since I lack the knowledge on how to automate these things).

enter image description here

Could you please tell me if automating a process such as this is at all possible in Photoshop and what methods/techniques might be used for this?

PS: If there is a graphical design software which is better suited for this task than photoshop which you know of please also let me know. Thank you


Here’s a script algorithm:

  1. Create a rectangular selection based on logo ratio (square in your example), size: I guess larger than half of a document?
  2. Check this rectangular selection against layer transparency (using an intersection operation).
  3. If there’s a selection in the result (which means that rectangular selection intersects with a layer), you need to create a contracted selection, 2 times smaller than before, storing the reductor.
  4. If there’s no selection, reductor is too big, reduce it and try again.
  5. When reductor is around 1-4 pixels, your rectangular selection should barely touch the layer. Use dimensions of this selection to transform your logo.
  6. repeat for all 4 corners of the image.

Update: Ok, here’s my variant. Not very fast (about five seconds for this image) but works.

enter image description here

Here’s the script (it uses my library which I didn’t include, but it’s easy to rewrite it including your own helper functions)

function main()
    var myLayer = L.getInfoTrgt(), // getting ID of the current layer to select it later
        myLogo = new File("/C/Users/Sergey Kritskiy/Desktop/temp/mylogo.jpg"); // path to logo

    for (var i = 0; i < 4; i++)
        var doc = new Doc(), // getting width/height and some other properties of the document
            size = {
                left: 0,
                top: 0,
                right: doc.w / 1.5,
                bottom: doc.w / 1.5, //presuming logo is square
            myCondition = false,
            difference = 50,
            counter = 0;

        L.selectById(; //make sure the original layer is selected

        while (!myCondition)
            D.rectSelection(size); //creating a rectangular selection using `size`
            L.loadSelection({operation: 'IntW'}); // loading selection from layer transparency using an `Intersection` operation
            var selection = D.getSelection(); //getting resulting selection coordinates: false if there's no selection

            if (selection == false) //no selection
                size.right = newSize.right // restore `size` from previous attempt
                size.bottom = newSize.bottom
                difference = difference / 2; // make difference smaller
            else //there's a selection
                newSize = U.cloneObject(size); // store this `size` attempt
                size.right -= difference //make selection `size` smaller
                size.bottom -= difference
            if (counter > 50 || difference < 1) myCondition = true; // if difference is small, it's enough

        L.placeSmartObject({path: myLogo}) // placing logo as a smart object

        var curLayer = L.getInfoTrgt(); // getting width, height of the layer, coordinates

                x: size.right / curLayer.width * 100,
                y: size.bottom / curLayer.height * 100,
            angle: 90 * i,
        }).alignTo("left top"); // scaling it to selection size, putting it to left corner of the document

        doc.rotate(90); //rotate document 90 degrees so that calculation would be always against top left corner of the document
app.activeDocument.suspendHistory("rotate", "main()");

Source : Link , Question Author : Maarten -Monica for president , Answer Author : Sergey Kritskiy

Leave a Comment