Skip to main content
Participating Frequently
September 22, 2022
Question

Trying to record w and h in info panel to create auto straighten object script in photoshop.

  • September 22, 2022
  • 2 replies
  • 724 views

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

 

 

This topic has been closed for replies.

2 replies

Inspiring
September 23, 2022

And for the theory behind this operation, you could check out this information:

 

https://en.wikipedia.org/wiki/Hough_transform

Chuck Uebele
Community Expert
Community Expert
September 23, 2022

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]
Participating Frequently
September 23, 2022

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?

Participating Frequently
September 23, 2022

Here is my visual representation...