check the width and height of an image
i am trying to check the width and height of an image in a directory by using python . the directory consist of two folders and each folder there are pictures want to check the width and height to resize them if they are not matched. here is my code:
def Resize(imageFolder, factor_1, factor_2): for path, dirs, files in os.walk(imageFolder): for fileName in files: image = Image.open(fileName) image_size = image.size width = image_size height = image_size if ((width and height) == 224): print("the width and height are equals") continue print("the width and height are not equals, so we should resize it") resize_pic(path, fileName, factor_1, factor_2)
when I run the code gives me error, i think the loop is not right. any help ?
Автор: mido Источник Размещён: 08.11.2019 11:15
Traceback (most recent call last): File "resize.py", line 62, in <module> Resize(imageFolder, resizeFactor , resizeFactor_h) File "resize.py", line 46, in Resize image = Image.open(fileName) File "/usr/lib/python2.7/dist-packages/PIL/Image.py", line 2028, in open raise IOError("cannot identify image file") IOError: cannot identify image file
for (pth, dirs, files) in os.walk(imageFolder): for fileName in files: image = Image.open(fileName) with Image.open(os.path.join(pth, fileName)) as image: image_size = image.size
You need provide the absolute path of the file as well like above.
Also check on image file formatАвтор: be_good_do_good Размещён: 20.08.2016 01:44