I am trying to rotate image, but I want to maintain the size of the Image. For example in the following example image, I want to see a complete rectangle and have no black background color after rotating.
Please help me, I'd appreciate it.
Now my code is:
src_im = Image.open("test.gif")
im = src_im.rotate(30)
im.save("result.gif")
To resize automatically, you want the expand
kwarg:
src_im = Image.open("test.gif")
im = src_im.rotate(30, expand=True)
im.save("result.gif")
As the PIL docs explain:
The expand argument, if true, indicates that the output image should be made large enough to hold the rotated image. If omitted or false, the output image has the same size as the input image.
On the black background, you need to specify the transparent colour when saving your GIF image:
transparency = im.info['transparency']
im.save('icon.gif', transparency=transparency)
try this one:
src_im = Image.open("test.jpg")
im = src_im.rotate(30,fillcolor='white', expand=True)
im.save("result.gif")
here comes the results:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With