[Error] AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

    728x90

    AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

     

    이런 에러가 발생하는 이유는 Python의 pillow package에 해당 모듈이 없다는 오류입니다. version에 따라 모듈이 삭제되기도 하는데, pillow 10.0.0에서는 'ANTIALIAS'의 모듈이 제거되었고, 'PIL.Image.LANCZOS' 또는 'PIL.Image.Resampling.LANCZOS'를 사용해야 합니다.

     

    원래의 알고리즘과 동일하여서 파일 내에서 수정을 하여도 되고,

    import PIL
    import numpy as np
    
    # Gradient image with a sharp color boundary across the diagonal
    large_arr = np.fromfunction(lambda x, y, z: (x+y)//(z+1),
                                (256, 256, 3)).astype(np.uint8)
    large_img = PIL.Image.fromarray(large_arr)
    
    # Resize it: PIL.Image.LANCZOS also works here
    small_img = large_img.resize((128, 128), PIL.Image.Resampling.LANCZOS)
    print(small_img.size)
    
    large_img.show()
    small_img.show()

     

    pillow의 버전을 낮추어도 상관이 없다면

     

    pip uninstall Pillow
    pip install Pillow==9.5.0

     

    OR

     

    pip3 install "Pillow<10.0.0"

     

    이 방법으로 해결할 수 있습니다.

     

    또는 파이썬 스크립트에서

     

    import PIL PIL.Image.ANTIALIAS = PIL.Image.LANCZOS

     

    이렇게 수정하여도 된다고 합니다.

     

    전 버전을 낮춰서 해결하였습니다.

     

     

    728x90

    댓글