This is not a complete answer, but I would take four corners, since the coordinates rotated them in your angle, and then calculated a new bounding box depending on the degree of the new coordinates. (assuming coordinates with a start in the lower left corner).
corners = rotate_each ( [(left,top) (left,bottom), (right,top), (right,bottom)], angle) new_bb_left = min([corners[0].x, corners[1].x, corners[2].x, corners[3].x]) new_bb_right = max([corners[0].x, corners[1].x, corners[2].x, corners[3].x]) new_bb_bottom = min([corners[0].y, corners[1].y, corners[2].y, corners[3].y]) new_bb_top = max([corners[0].y, corners[1].y, corners[2].y, corners[3].y])
Charles Beattie
source share