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

  • 5
    It cannot be done as the "script" cannot detect edges, and then calculate biggest surface from "corners" and fill it. It would require custom script or even whole new program. Nov 26, 2018 at 13:26
  • Good luck with that !! :)
    – Lucian
    Nov 26, 2018 at 13:27
  • @SZCZERZOKŁY I might be able to determine what corner the logo should be in and what size/position the logo should have in the software that produces the base images (the software which I use for making the renderings/base image is 3d studio max). If I were to store this information (scale and position where the logo should be) in a text file, could I insert the logo into the base image, scale it with a factor and position it to the correct coordinates (the correct position coordinates and scale factor would be written in the a fore mentioned text file). Nov 26, 2018 at 15:39

1 Answer 1


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(myLayer.id); //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()");
  • This looks like a very fun and rewarding project for the OP. If I was not super busy this month, I would like to have tried to practice my PS scripting by trying this myself :)
    – Silly-V
    Nov 26, 2018 at 16:50
  • I updated my answer with my script, I guess it's quite terrible :) but it works Nov 27, 2018 at 10:37
  • 1
    The picture alone gets an upvote from me.
    – Joonas
    Nov 27, 2018 at 12:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.