Image rotation * without resizing

I would like to rotate the image (with a given rotation angle), but without reducing the size of the image.

  • what is already happening, saving the shaded area as a smaller image
  • - this is what I would like, the dashed line is the new image size.

The server has PHP 5.3+. Links, code and explanations are very welcome.

+7
source share
3 answers

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]) 
+2
source

This may be the way to do it. Calculate the width of the diagonal.

Check this image for the formula

PHP has a square root function: http://se2.php.net/manual/en/function.sqrt.php So you must have a diagonal width that you could apply on the converted image.

+1
source
0
source

All Articles