I have a site where one of the features lets users upload images, then rotate/crop them. I'm using the following tools:
So let's say a user wants to crop the image first, then rotate it. Cropping gives a set of coordinates from the top left of the image that form a rectangle in the format x1,y1,x2,y2
. I store that as a string in a database field and then append it to my call to ImageResizer like so:
http://www.url.com/assets/image.jpg?crop=x1,y1,x2,y2
However, if a user wants to rotate the image after having cropped it, those coordinates no longer apply. What I'd like to do is to split my coordinate string up into an integer array that contains x1,y1,x2,y2 in order.
My question is: is there a mathematical formula I can apply to those values based upon 90 or -90 degrees of rotation that will give me the correct coordinate values after rotation?
I only allow rotation in 90 degree increments and only one at a time - so from 0 to 90, then again from 90 to 180 if you wanted to flip it.