Calculate Bounding box coordinates from a rotated rectangle

Transform the coordinates of all four corners Find the smallest of all four x’s as min_x Find the largest of all four x’s and call it max_x Ditto with the y’s Your bounding box is (min_x,min_y), (min_x,max_y), (max_x,max_y), (max_x,min_y) AFAIK, there isn’t any royal road that will get you there much faster. If you are … Read more

How do I rotate an image around its center using Pygame?

Short answer: Get the rectangle of the original image and set the position. Get the rectangle of the rotated image and set the center position through the center of the original rectangle. Return a tuple of the rotated image and the rectangle: def rot_center(image, angle, x, y): rotated_image = pygame.transform.rotate(image, angle) new_rect = rotated_image.get_rect(center = … Read more

Python list rotation [duplicate]

def rotate(l, n): return l[-n:] + l[:-n] More conventional direction: def rotate(l, n): return l[n:] + l[:n] Example: example_list = [1, 2, 3, 4, 5] rotate(example_list, 2) # [3, 4, 5, 1, 2] The arguments to rotate are a list and an integer denoting the shift. The function creates two new lists using slicing and … Read more

CSS rotate property in IE

To rotate by 45 degrees in IE, you need the following code in your stylesheet: filter: progid:DXImageTransform.Microsoft.Matrix(sizingMethod=’auto expand’, M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476); /* IE6,IE7 */ -ms-filter: “progid:DXImageTransform.Microsoft.Matrix(SizingMethod=’auto expand’, M11=0.7071067811865476, M12=-0.7071067811865475, M21=0.7071067811865475, M22=0.7071067811865476)”; /* IE8 */ You’ll note from the above that IE8 has different syntax to IE6/7. You need to supply both lines of code … Read more

HTML5 Canvas Rotate Image

You can use canvas’ context.translate & context.rotate to do rotate your image Here’s a function to draw an image that is rotated by the specified degrees: function drawRotated(degrees){ context.clearRect(0,0,canvas.width,canvas.height); // save the unrotated context of the canvas so we can restore it later // the alternative is to untranslate & unrotate after drawing context.save(); // … Read more

JS Client-Side Exif Orientation: Rotate and Mirror JPEG Images

The github project JavaScript-Load-Image provides a complete solution to the EXIF orientation problem, correctly rotating/mirroring images for all 8 exif orientations. See the online demo of javascript exif orientation The image is drawn onto an HTML5 canvas. Its correct rendering is implemented in js/load-image-orientation.js through canvas operations. Hope this saves somebody else some time, and … Read more