0
#!/usr/bin/python
from PIL import Image
import os, sys

path = "C:/Users/nonono/Desktop/hypergan/data/trainingData/"
dirs = os.listdir( path )

def resize():
    for item in dirs:
        if os.path.isfile(path+item):
            im = Image.open(path+item)
            f, e = os.path.splitext(path+item)
            imResize = im.resize((256,256), Image.ANTIALIAS)
            imResize.save(f + ' resized.jpg', 'JPEG', quality=90)

resize()

i got this code from another answer here and fitted it to my own parameters, yet when i run it in the command line i get an error:

Traceback (most recent call last):
  File "resize.py", line 16, in <module>
    resize()
  File "resize.py", line 11, in resize
    im = Image.open(path+item)
  File "C:\Users\nonono\AppData\Local\Programs\Python\Python37\lib\site-packages\PIL\Image.py", line 2822, in open
    raise IOError("cannot identify image file %r" % (filename if filename else fp))
OSError: cannot identify image file 'C:/Users/nonono/Desktop/hypergan/data/trainingData/bx71zze7egy18wel231 resized.jpg'

the folder trainingData is filled with a large amount of images, that i want to resize to 256x256 regardless of aspect ratio, i will not need the images afterwards so if there is a way to replace the images instead of just copying, resizing, and renaming, that would be great (unless i am reading this incorrectly, i have about 2 weeks experience in python)

any help would be appreciated

chaps
  • 105
  • 8
  • +Vasilis G. same error, except it has an underscore instead of a space where logic implies it would be – chaps Sep 28 '19 at 09:02
  • There's seems to be a known PIL issue. You can check it out [here](https://github.com/python-pillow/Pillow/issues/3287). – Vasilis G. Sep 28 '19 at 09:04
  • +Vasilis G. thanks, but where would i put `ImageFile.LOAD_TRUNCATED_IMAGES = True`? and which variable should i replace `ImageFile` with? – chaps Sep 28 '19 at 09:07
  • I haven't come across this problem, but I think you need to add it right after your imports. – Vasilis G. Sep 28 '19 at 09:15

0 Answers0