rwilliams
rwilliams

Reputation: 91

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'

Upvotes: 0

Views: 410

Answers (1)

Ollie in PGH
Ollie in PGH

Reputation: 2629

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.

Upvotes: 1

Related Questions