Agamnentzar / ag-psd

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

Calculating Width and Height of Shape from PSD Data #167

Open AlaaBol opened 5 months ago

AlaaBol commented 5 months ago

Could you please provide guidance on the correct method for calculating the width and height of a shape from the PSD data? Specifically, should I use the bounding box coordinates or the vertices of the shape for this calculation?

03-19-48-DESKTOP-6L1HFJK-Administrator-Access-Getscreen-me

Agamnentzar commented 5 months ago

Vertices of the shape will not give you correct bounds because bezier curves can extend beyond position of the points. You can probably use bounding box coordinates if you don't plan on modifying the shape. Otherwise you'll have to somehow calculate bounds for each bezier curve and pick maximum extents from that. I don't know how to calculate it but calculating bounds of bezier curve should be a common problem that has some solutions online.

AlaaBol commented 5 months ago

Thank you for your response. Simply obtaining the width and height of a shape from the bounding vertices isn't giving correct results. This is because when the shape is rotated, the bounding box tends to expand, potentially distorting the actual dimensions of the shape itself. What alternative methods or adjustments would you suggest to accurately determine the width and height of the shape, especially considering rotations?

Agamnentzar commented 5 months ago

I'm not really familiar with your problem and don't really know what's the best approach.