Skip to main content
Legend
February 19, 2020
Answered

Is there a way to get the transformation ratio of a smart object?

  • February 19, 2020
  • 1 reply
  • 1138 views

I am writing a script that adjusts the layers size and position. There are no problems with pixel layers, but there is a problem with smart objects: they can be in a document with a transformation already done, information about which is stored in the layer settings.

 

In the smartObjectMore object, I can get information about the initial size of the layer (size) and the coordinates of the node points of the object (transform (ActionList)), but I can’t figure out how to calculate the transformation coefficient of the layer based on this data?  (I'm only interested in the simplest cases of transformation without changing the proportions).

 

This topic has been closed for replies.
Correct answer jazz-y

UPD: seems to understand - knowing the coordinates of the vertices you need to find the lengths of the sides and correlate them with the original image size

 

transformation  ratio = size / (Math.sqrt (Math.pow(x2-x1,2) + Math.pow(y2-y1,2) ))

1 reply

jazz-yAuthorCorrect answer
Legend
February 19, 2020

UPD: seems to understand - knowing the coordinates of the vertices you need to find the lengths of the sides and correlate them with the original image size

 

transformation  ratio = size / (Math.sqrt (Math.pow(x2-x1,2) + Math.pow(y2-y1,2) ))

JJMack
Community Expert
Community Expert
February 19, 2020

Smart object layers have a layer transform associated with them. This transform can scale, rotate and distort the layers pixels that are a transformation of the pixels rendered for the layers object.   So the layers bounds are for the transformed pixels.   Not the layer object. R-bin posted some script code to get the 4 corners of the smart object transform and may have been also able the get the transform warp information. However, I would not know what to do with the warp information. Here are some screen captures. I start with as small rectangle 50% gray layer I converted to a smart object layer  that I transformed, rotated, distorted and warped.  I then ran a Script that showed and marked the Layers bounds. After the I showed the Layers transform bounding box,  Than I showed the  Transform Warp controls.  And then ran a script the contained  r-bin code to get the transform controls 4 corners. You can calculate distances and slope directions.  I would not know how to get the small rectangle object back squared to the canvas not rotated warped and distorted.  If the 4 corners angles are  9- degrees and the slopes are horizontal and vertical. The object may not be  warped.  You can then use the layers bounds to get the layers current size then transform the layer to 100% Width and Height to to see if the object had been scaled or distorted. by getting the  full size layers bounds.  If the object was warped you may be able to removed that by resetting the transform warp settings. I have never programmed a warp or understand all that r-bin code retrieved.  That's above my pay grade.

 

 

JJMack