PYTHON PROGRAM TO ROTATE AN IMAGE

In this tutorial, we will discuss how to rotate an image by using the Python program. It is very easy to rotate an image by Python code

  • Prerequisite: Install pillow library, to install run the following command:
pip install pillow
  • Import the Image  PIL(Python Imaging Library) import module we can solve the program
from PIL import Image
  • PIL.Image.open(): Opens and identifies the given image file. This is a lazy operation; this function determines the file, but the file remains open, and actual image data is not read from the file until you try to process the data (or call the load() method) .
image=Image.open("https://www.codespeedy.com/wp-content/themes/CodeSpeedy-March-2019/img/logo/CodeSpeedy-Logo.png")
  • To rotate this image proved this arguments angle, expand, center, fillcolor of an image and assign them to variables.
rotating=image.rotate(angle, expand = 0,center=None, fillcolor = None)
  • angle – In degrees counter clockwise
  • expand – Optional expansion flag. If  true, expands the output image to make it large enough to hold the entire rotated image. If  false make the output image the same size as the input image.
  • center – Optional center of rotate. Origin is the upper left corner. Default is the center of  the image.
  • fillcolor – An optional color for area outside the rotate image.
  • and print the statements.
print(rotating)
  • Final code will be like this:
    from PIL import Image
    image=Image.open("https://www.codespeedy.com/wp-content/themes/CodeSpeedy-March-2019/img/logo/CodeSpeedy-Logo.png")
    rotating=image.rotate(50,expand=True,center=None,fillcolor=None)
    print(rotating)

    Final output:
    Image is turns to 50 degrees

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top