Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AbhilashG97 opened this issue Mar 18, 2020 · 1 comment
Open

Comments

@AbhilashG97
Copy link

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.

@patrickscottbest
Copy link

Same same. Lovely little script, but maybe for now i have to skip the valide and just "try" and catch the exception I guess?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants