• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Sep 22, 2022 Sep 22, 2022

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

 

 

TOPICS
Actions and scripting , SDK , Windows

Views

264

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Sep 22, 2022 Sep 22, 2022

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]

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 23, 2022 Sep 23, 2022

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 23, 2022 Sep 23, 2022

Copy link to clipboard

Copied

Here is my visual representation...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 23, 2022 Sep 23, 2022

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 24, 2022 Sep 24, 2022

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 24, 2022 Sep 24, 2022

Copy link to clipboard

Copied

Yes, Javascript is used to get the height. I would start with this:

 

https://www.google.com/url?sa=t&source=web&rct=j&url=https://blog.cutterman.cn/assets/files/photosho...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Sep 24, 2022 Sep 24, 2022

Copy link to clipboard

Copied

LATEST

Many thanks for your help Chuck !!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 23, 2022 Sep 23, 2022

Copy link to clipboard

Copied

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

 

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines