neutronX / django-markdownx

Comprehensive Markdown plugin built for Django
https://neutronx.github.io/django-markdownx/
Other
863 stars 153 forks source link

AttributeError when using pillow >=10.0 #256

Closed max747 closed 1 year ago

max747 commented 1 year ago

If pillow 10.0.0 or greater version is installed, django-markdownx raises AttributeError when uploading a large size image by drag & drop to a form that is related to the markdownx widget. This occurs when the image is resized. https://github.com/neutronX/django-markdownx/blob/v4.0.2/markdownx/utils.py#L123-L124

PIL.Image.ANTIALIAS has been removed at pillow 10.0.0. https://pillow.readthedocs.io/en/stable/releasenotes/10.0.0.html#constants

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 197, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 104, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/generic/base.py", line 143, in dispatch
    return handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/generic/edit.py", line 153, in post
    return self.form_valid(form)
  File "/usr/local/lib/python3.9/site-packages/markdownx/views.py", line 81, in form_valid
    image_path = form.save(commit=True)
  File "/usr/local/lib/python3.9/site-packages/markdownx/forms.py", line 61, in save
    image = self._process_raster(image, image_extension)
  File "/usr/local/lib/python3.9/site-packages/markdownx/forms.py", line 134, in _process_raster
    preped_image = scale_and_crop(image, **MARKDOWNX_IMAGE_MAX_SIZE)
  File "/usr/local/lib/python3.9/site-packages/markdownx/utils.py", line 124, in scale_and_crop
    im = _scale(im=im, x=source_x * scale, y=source_y * scale)
  File "/usr/local/lib/python3.9/site-packages/markdownx/utils.py", line 77, in _scale
    resample=Image.ANTIALIAS
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

Until django-markdownx supports pillow 10.0.0, it would be better to limit pillow version to <10.0 using requirements.txt.

environment