Rotate image *without* resizing it

I would like to rotate an image (with a user-defined angle of rotation), but without making the image smaller.

  • is what happens already, saving the shaded area as a smaller image
  • is what I would like, the dashed line being the new image size.
  • The server has PHP 5.3+. Links, code and explanations all very welcome.


    This is not complete answer but I would take the four corners as coordinates rotate them by your angle and then calculate the new bounding box based on the extent of the new coordinates. (assuming coordinates with origin on the bottom left).

    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])
    

    This could be a way to do it. Calculate the diagonal width.

    PHP has a Square root function: http://se2.php.net/manual/en/function.sqrt.php In that way you should have the diagonal width which you could apply on the transformed image.


    There are many solutions including the trigonometric formulas but this library seems to be the shortcut.

    http://wideimage.sourceforge.net/

    Example: http://wideimage.sourceforge.net/wp-content/current/demo/index.php?demo=rotate&output=preset%20for%20demo&colors=255&dither=1&match_palette=1

    链接地址: http://www.djcxy.com/p/10498.html

    上一篇: 通过HttpURLConnection进行浏览器身份验证

    下一篇: 旋转图像*无需调整大小