简体   繁体   中英

Image rotation error using PIL because of exif metadata of images

I am trying to stop auto-rotation of the images in a particular folder. As I'm using win7 64 bit in folder it says all correct once its uploaded to dropbox.

The rotation of image from 90 to 180 degree displays. With this python 3 code I'm trying to achieve the 90 auto rotation for all my images in the folder. However I am getting this error. Please check and let me know how could I achieve this.

Here is the code that I am applying to it:

from PIL import Image
import os

image1 = Image.open('.JPG')
image1.rotate(90).save('.JPG')

Following is the error:

Traceback (most recent call last):
  File "C:\Users\Dell 2\Desktop\14th Feb., 2020\183ND750\pil_demo.py", line 4, in <module>
    image1 = Image.open('.JPG')
  File "C:\Users\Dell 2\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\Image.py", line 2809, in open
    fp = builtins.open(filename, "rb")
FileNotFoundError: [Errno 2] No such file or directory: '.JPG'

You're not giving it an image to work with. ('.JPG') doesn't open an image in the folder. You want to pass a file path. Something like.

from PIL import Image
import os

image1 = Image.open('C:\Users\YourUser\Desktop\pics\my_image.jpg')
image1.rotate(90).save('C:\Users\YourUser\Desktop\pics\my_image.jpg')

Those calls to open() and save() interact with your computer's file system.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM