Rotate & trim image

After rotating background image and trim to the body bounds, the bounds are totally different.

the crop is appleid before the rotation. So this is as expected, even if it is not nice.

Thanks. Then how can I get it right via scripting? Is there enough framework available to achieve it? (Maybe not, I presume the trim bounds cannot be rotated)

Yes. Maybe re-rotate the image in Photoshop.