rotation - Rotate a image and fill screen in python -
i trying rotate photo fill whole frame (in case 720x480 window). when use default image.rotate function pil/pillow in code fragment below:
file = image.open("test.jpg") out = file.rotate(45, expand = 1) out.save(work_dir+foreground,quality=100)
i result in photo 1 rotates photo within box. i'd rotate fills whole box (i dont mind cropping) in photo 2 there way that?
found cheap solution square images:
def rotate_image_square(im, deg): im2 = im.rotate(deg, expand=1) im = im.rotate(deg, expand=0) width, height = im.size assert (width == height) rads = math.radians(deg) new_width = width - (im2.size[0]-width) left = top = int((width - new_width)/2) right = bottom = int((width + new_width)/2) return im.crop((left, top, right, bottom))
Comments
Post a Comment