Copy link to clipboard
Copied
I am trying to create a script to auto straighten items in ps cc. (note "crop & straighten" automation works well but not 100%; also note I can achieve this in lightroom but want to keep the process in cc).
The basic question I am asking is how to I record w and h values of selected items in the F8 info panel. I want to compare two h values and then return a command to photoshop to rotate an item based on the result. Is this done with javascript? VB? Where is a good resource to learn how to do this? I know my way around cc but know little about coding andmy coder is not familiar with cc. The explanation for why I am doing this is below...
Items I want to auto straighten are individual artworks on greenscreen background. After removing background I am left with an item which will be usually slightly skewed. To auto straighten the item I need to know the top left and top right information for the item so I can calculate the degree of rotation needed to auto straighten. CC doesnt seem to have an option to give this info. Cntl T doesnt reveal the lower of the two points.
But I have a work around. I use "Image>Canvas size" and remove 95 percent of the left hand side of the image. Then "Image>Trim" to remove any blank space above.
I then undo the canvas size and repeat that process after remopving 95% of the right hand side of the image.
I can then compare the height of the trimmed ( Image>Trim) left and right sides. If left is 30 pixels shorter than the right then I know I have to rotate the left 15 pixels up to straighten the image.
Thanks
Copy link to clipboard
Copied
You can use the dimensions of a layer using "bounds" which will give you an array of the coordinates. The 0 part of the array is the width left side. 2 is the width right side. 1 is height top, and 3 is height bottom. Subtracting these numbers give you the actual dimension.
var doc = activeDocument
var lay= doc.activeLayer
var layHeight = lay.bounds[3]- lay.bounds[1]
Copy link to clipboard
Copied
Unless I misunderstood isnt that essentially drawing a rectangle around the object? It would give the height of the higher side of the skew but not the height of the lower side of the skew?
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Yes, to both your illustrations. If you do as you mentioned by cropping the left and right part's of the layer, you will get a different value for the height of the two sides, which you can then use to calculate the angle for rotation.
Copy link to clipboard
Copied
Thanks Chuck for the info. My main question is which language to capture the height info? Is that javascript? I have no experience with coding photoshop. Any good links for an overview of how to proceed? Thanks.
Copy link to clipboard
Copied
Yes, Javascript is used to get the height. I would start with this:
Copy link to clipboard
Copied
Many thanks for your help Chuck !!
Copy link to clipboard
Copied
And for the theory behind this operation, you could check out this information: