Skip to content

AttributeError: 'function' object has no attribute 'validate' #30

@AbhilashG001

Description

@AbhilashG001

I'm trying to resize a set of images. I followed the code mentioned here, but I keep getting this error.

The code snippet which results in the above-mentioned error is as follows -

from PIL import Image
from resizeimage import resizeimage

def resize_images(root_image_path, resized_image_path):
    for image_folder in os.listdir(root_image_path):
        
        # create corresponding folders in the resized_images folder
        if not os.path.exists(os.path.join(resize_image_path, image_folder)):
            os.makedirs(os.path.join(resize_image_path, image_folder))
                        
        # resize all images to 256 x 256
        for image in os.listdir(os.path.join(root_image_path, image_folder)):
            img = Image.open(os.path.join(root_image_path, image_folder, image), 'r')
            
            # check if image can be resized i.e. if it is too small or not
            is_valid = resizeimage.resize_cover.validate(img, [256, 256])
            
            if is_valid:
                # if image is valid, resize it to 256 x 256
                img = resizeimage.resize_cover(img, [256, 256], validate=False)
                img = img.convert("RGB")
                img.save(os.path.join(resized_image_path, image_folder, image), img.format)
            else:
                # if the image is too small, scale it up
                img = resizeimage.resize_contain(img, [256, 256], validate=False)
                img = img.convert("RGB")
                img.save(os.path.join(resized_image_path, image_folder, image), img.format)
                
                        
        print('{} done!'.format(image_folder))
    print('Resizing images complete!')

The error message that I get is shown below -

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-21-67bef302aaa0> in <module>
----> 1 resize_images(os.path.join(os.getcwd(), 'data/images/'), resize_image_path)

<ipython-input-18-2856c9fdcdb0> in resize_images(root_image_path, resized_image_path)
     16 
     17             # check if image can be resized i.e. if it is too small or not
---> 18             is_valid = resizeimage.resize_cover.validate(img, [256, 256])
     19 
     20             if is_valid:

AttributeError: 'function' object has no attribute 'validate'

Am I doing something wrong?
Thank you so much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions