Welcome folks today in this blog post we will be rotating images
at any direction in python using pypdf2 library
. All the full source code of the application will be given below.
Get Started
In order to get started you need to install the following library using the pip
command as shown below
pip install pypdf2
After installing this library make an app.py
file and copy paste the following code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# import the Python Image processing Library from PIL import Image # Create an Image object from an Image colorImage = Image.open("profile.jpg") # Rotate it by 45 degrees rotated = colorImage.rotate(45) # Rotate it by 90 degrees transposed = colorImage.transpose(Image.ROTATE_90) # Display the Original Image colorImage.show() # Display the Image rotated by 45 degrees rotated.show() rotated.save("rotate.jpg") # Display the Image rotated by 90 degrees transposed.show() |
As you can see in the above python
script we are rotating the image
at an angle of 45 degree
you can change the value accordingly as you want. And lastly we are saving the image with the custom name in the root directory and also displaying it also as shown below
If you run the python script by typing the below command
python app.py