-
-
Save leonardreidy/2dcca95a7c14b485dcee06792c6f14e9 to your computer and use it in GitHub Desktop.
# pip install Pillow if you don't already have it | |
# import image utilities | |
from PIL import Image | |
# import os utilities | |
import os | |
# define a function that rotates images in the current directory | |
# given the rotation in degrees as a parameter | |
def rotateImages(rotationAmt): | |
# for each image in the current directory | |
for image in os.listdir(os.getcwd()): | |
# open the image | |
img = Image.open(image) | |
# rotate and save the image with the same filename | |
img.rotate(rotationAmt).save(image) | |
# close the image | |
img.close() | |
# examples of use | |
rotateImages(90) | |
rotateImages(180) | |
rotateImages(270) |
Thanks!
Thank you!
thx, very useful and simple
I am trying to implement the code in windows, where I will include my data path in the code?
Thanks bro! I was just looking for this! Why? I had an assignement and i needed a workbook from the past year. I hadnt it so a friend sent me photos of each page, but turned 90º degrees to the right!
How do do this while saving the image with different name so you have double the image but with different orientation. Tried to do but just not getting the part with saving the image as a different image.
How do do this while saving the image with different name so you have double the image but with different orientation. Tried to do but just not getting the part with saving the image as a different image.
img = Image.open(image_path)
temp_rot_image = img.rotate(rotation_amt)
new_image_folder= 'data\Kaggle\aug_images\'+str(temp_idx) # edit here with the preferred image folder
if not os.path.exists(new_image_folder): # additional, creating folder if not existed
os.makedirs(new_image_folder)
temp_rot_image.save(os.path.join(new_image_folder, new_image_name)) # save roatetd image
Thanks!