Agamnentzar / ag-psd

Javascript library for reading and writing PSD files
Other
496 stars 66 forks source link

how to read the rotation of layer? #161

Open dogeFu opened 10 months ago

dogeFu commented 10 months ago

image

I read the readme_psd.md,failed to find where to get to rotaion of a layer,can you help me?

Agamnentzar commented 10 months ago

I don't think this value is stored anywhere in PSD file, it's calculated back from the transform (placedLayer.transform) that specifies location of 4 corners of transformation cage.

zms664011036 commented 7 months ago

hello, transform= [12391.430367826988, 1721.516648354885, 2447.364078652975, 8802.809486322956, -70.25686706304622, 5075.064425643115, 9873.809422110964, -2006.2284123249551];) The four corners, how to calculate the rotation Angle, can provide the code to calculate the Angle?

The following is my code, but the calculation will be a little error, can you help me to see what went wrong?

image

const angle = getAngle({ x: 0, y: img.height, }, { x: transform[6] - transform[0], y: transform[7] - transform[1], });

function getAngle({x: x1, y: y1}, {x: x2, y: y2}) { const dot = x1 x2 + y1 y2 const det = x1 y2 - y1 x2 const angle = Math.atan2(det, dot) / Math.PI * 180 return angle }