2

I'm wondering if there is a way to setup an Action in CS6 that would be able to determine the dimensions of an image or layer?

Ultimately, I'd like to create a watermark essentially which would stamp the image with its own dimensions.

Any help appreciated.

0

1 Answer 1

6

I'm not sure that an action is necessarily the best option for you. A script could do something like this fairly easily. This should give you some useful pointers as far as basic scripting goes..

Basically, the script has to do a few things. First, get the layer dimensions and save them as a variable. Then, make a new text layer, and use the variables as that text.

Below is the basic skeleton of the script:

function run(){
    var layer = activeDocument.activeLayer; //Grab the currently selected layer

    //Calculate length and width based on the rectangular bounds of the selected layer
    var length = layer.bounds[2]-layer.bounds[0]; //Grab the length
    var width = layer.bounds[3]-layer.bounds[1]; //Grab the width

    //Create a text layer
    var textLayer = activeDocument.artLayers.add(); //Make a new layer on the canvas
    textLayer.kind = LayerKind.TEXT; //Make that layer a text layer
    textLayer.name = "Dimensions"; //Name the layer "Dimensions"
    var textReference = textLayer.textItem; //Create a textItem which we'll use to fill the text layer
    textReference.contents = "Length: " + length + " Width: " + width; //Set the contents of that textItem to the length and width

}
run();

You can run this by copying and pasting this code into a file named "dimensions.jsx", then going to File->Scripts->Browse and navigating to that script.

Below is "proof" that this works - I created a new layer named Layer 1, and selected it. In the "Info" panel, you can see the length and width listed. I then ran the script, which created a new layer named Dimensions, whose text contents are the same length and width presented in the Info panel (without the rounding). Proof

Let me know if you have any other questions!

4
  • Interesting. I wasn't aware of scripts. I guess I would still be able to create a droplet using the script?
    – skube
    Sep 11, 2013 at 22:35
  • What exactly is the end-goal here? You certainly could make an action/droplet that runs the script. You could also program the script to ask you for a folder, so that when you select the folder, the script is run on every image in that folder (there are code tutorials online to get that to work, although I don't know how much programming experience you have).
    – Jake
    Sep 11, 2013 at 22:51
  • The end goal is to easily watermark any image (any dimension, any file type) with its own dimensions.
    – skube
    Sep 12, 2013 at 13:39
  • Ok, then yes with this simple script installed (adobe.com/devnet/photoshop/scripting.html, look in the CS6 section for the Script Listener plugin), you should be able to go to File->Scripts and choose the installed script, thus watermarking that image with its dimensions. As long as Photoshop can open the image (any file type), it should work just fine. You can also create a droplet/action that runs the script if that's easier for you to access.
    – Jake
    Sep 12, 2013 at 14:43

Your Answer

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

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