Repository: django-cms/django-filer

Issue:
UnidentifiedImageError when uploading an SVG
Steps to reproduce:

- Load up any folder in Filer
- Upload the below SVG image
- Result is UnidentifiedImageError and the inability to browse any folders that contain said image.

![AJ_Digital_Camera](https://user-images.githubusercontent.com/1115667/186635856-81ccc7c9-37f1-41ab-adab-3035eceb6675.svg)
 
Tested on:
- Django 3.2.15.0
- Django CMS 3.11.0.1
- Filer 2.2.3

I can provide a link to a bare-bones project that reproduces the issue reliably.


Discussion:
<img width="1433" alt="image" src="https://user-images.githubusercontent.com/1115667/186637182-41c0d204-b17c-40a1-b9ae-439282486550.png">

```Environment:


Request Method: GET
Request URL: https://filer-22-stage.us.aldryn.io/en/admin/filer/folder/1/list/

Django Version: 3.2.15
Python Version: 3.9.6
Installed Applications:
['aldryn_addons',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.messages',
 'aldryn_sso',
 'djangocms_admin_style',
 'django.contrib.admin',
 'django.contrib.staticfiles',
 'aldryn_django',
 'aldryn_sites',
 'cms',
 'aldryn_django_cms',
 'menus',
 'sekizai',
 'treebeard',
 'parler',
 'django.contrib.sitemaps',
 'compressor',
 'robots',
 'captcha',
 'django_select2',
 'filer.contrib.django_cms',
 'djangocms_text_ckeditor',
 'filer',
 'easy_thumbnails',
 'mptt',
 'polymorphic']
Installed Middleware:
['cms.middleware.utils.ApphookReloadMiddleware',
 'django.middleware.gzip.GZipMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'aldryn_sso.middleware.AccessControlMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.locale.LocaleMiddleware',
 'django.contrib.sites.middleware.CurrentSiteMiddleware',
 'aldryn_sites.middleware.SiteMiddleware',
 'django.middleware.security.SecurityMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'cms.middleware.user.CurrentUserMiddleware',
 'cms.middleware.page.CurrentPageMiddleware',
 'cms.middleware.toolbar.ToolbarMiddleware',
 'cms.middleware.language.LanguageCookieMiddleware']


Template error:
In template /usr/local/lib/python3.9/site-packages/filer/templates/admin/filer/folder/directory_table.html, error at line 106
   cannot identify image file <_io.BytesIO object at 0x7faf6c2d7810>
   96 :                                 {% endif %}
   97 :                             </td>
   98 :                             <td class="column-icon">
   99 :                                 {% if is_popup and filer_admin_context.pick_file %}
   100 :                                     <a href="#" onclick="opener.dismissRelatedImageLookupPopup(window, {{ file.id|unlocalize }}, '{% file_icon_url file %}', '{{ file.label|escapejs }}'); return false;"
   101 :                                         title="{% trans 'Select this file' %}">
   102 :                                 {% elif has_change_permission %}
   103 :                                     <a href="{{ file.get_admin_change_url }}{% filer_admin_context_url_params %}"
   104 :                                             title="{% blocktrans with file.label as item_label %}Change '{{ item_label }}' details{% endblocktrans %}">
   105 :                                 {% endif %}
   106 :                                  {% file_icon file %} 
   107 :                                 {% if has_change_permission or is_popup and filer_admin_context.pick_file %}
   108 :                                     </a>
   109 :                                 {% endif %}
   110 :                             </td>
   111 :                             <td class="column-name">
   112 :                                 <div>
   113 :                                     <strong>
   114 :                                         {% if is_popup and filer_admin_context.pick_file %}
   115 :                                             <a href="#" onclick="opener.dismissRelatedImageLookupPopup(window, {{ file.id|unlocalize }}, '{% file_icon_url file %}', '{{ file.label|escapejs }}'); return false;"
   116 :                                                 title="{% trans 'Select this file' %}">


Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.9/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/utils/decorators.py", line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/django/contrib/admin/sites.py", line 232, in inner
    return view(request, *args, **kwargs)
  File "/usr/local/lib/python3.9/site-packages/filer/admin/folderadmin.py", line 443, in directory_listing
    return render(request, self.directory_listing_template, context)
  File "/usr/local/lib/python3.9/site-packages/django/shortcuts.py", line 19, in render
    content = loader.render_to_string(template_name, context, request, using=using)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader.py", line 62, in render_to_string
    return template.render(context, request)
  File "/usr/local/lib/python3.9/site-packages/django/template/backends/django.py", line 61, in render
    return self.template.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 170, in render
    return self._render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 150, in render
    return compiled_parent._render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 62, in render
    result = block.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/loader_tags.py", line 195, in render
    return template.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 172, in render
    return self._render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 162, in _render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/defaulttags.py", line 214, in render
    nodelist.append(node.render_annotated(context))
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/defaulttags.py", line 315, in render
    return nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/defaulttags.py", line 519, in render
    return self.nodelist.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 938, in render
    bit = node.render_annotated(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/base.py", line 905, in render_annotated
    return self.render(context)
  File "/usr/local/lib/python3.9/site-packages/django/template/library.py", line 214, in render
    _dict = self.func(*resolved_args, **resolved_kwargs)
  File "/usr/local/lib/python3.9/site-packages/filer/templatetags/filer_admin_tags.py", line 120, in file_icon
    return file_icon_context(file, detail, width, height)
  File "/usr/local/lib/python3.9/site-packages/filer/templatetags/filer_admin_tags.py", line 94, in file_icon_context
    icon_url = thumbnailer.get_thumbnail(opts).url
  File "/usr/local/lib/python3.9/site-packages/easy_thumbnails/files.py", line 508, in get_thumbnail
    thumbnail = self.generate_thumbnail(
  File "/usr/local/lib/python3.9/site-packages/easy_thumbnails/files.py", line 382, in generate_thumbnail
    image = engine.generate_source_image(
  File "/usr/local/lib/python3.9/site-packages/easy_thumbnails/engine.py", line 112, in generate_source_image
    image = generator(source, **processor_options)
  File "/usr/local/lib/python3.9/site-packages/easy_thumbnails/source_generators.py", line 27, in pil_image
    image = Image.open(source)
  File "/usr/local/lib/python3.9/site-packages/PIL/Image.py", line 3147, in open
    raise UnidentifiedImageError(

Exception Type: UnidentifiedImageError at /en/admin/filer/folder/1/list/
Exception Value: cannot identify image file <_io.BytesIO object at 0x7faf6c2d7810>
```

Resolving patch:
diff --git a/aldryn_config.py b/aldryn_config.py
--- a/aldryn_config.py
+++ b/aldryn_config.py
@@ -8,7 +8,9 @@ def to_settings(self, data, settings):
 
         from aldryn_addons.utils import boolean_ish, djsenv
         from aldryn_django import storage
+        from easy_thumbnails.conf import Settings as EasySettings
 
+        EasyThumbnailSettings = EasySettings(isolated=True)
         env = partial(djsenv, settings=settings)
 
         # django-filer
@@ -29,17 +31,16 @@ def to_settings(self, data, settings):
         # easy-thumbnails
         settings['THUMBNAIL_QUALITY'] = env('THUMBNAIL_QUALITY', 90)
         settings['THUMBNAIL_PRESERVE_EXTENSIONS'] = ['png', 'gif']
-        settings['THUMBNAIL_PROCESSORS'] = (
-            'easy_thumbnails.processors.colorspace',
-            'easy_thumbnails.processors.autocrop',
-            'filer.thumbnail_processors.scale_and_crop_with_subject_location',
-            'easy_thumbnails.processors.filters',
-        )
-        settings['THUMBNAIL_SOURCE_GENERATORS'] = (
-            'easy_thumbnails.source_generators.pil_image',
-        )
         settings['THUMBNAIL_CACHE_DIMENSIONS'] = True
 
+        # Swap scale and crop for django-filer version
+        settings['THUMBNAIL_PROCESSORS'] = tuple([
+            processor
+            if processor != 'easy_thumbnails.processors.scale_and_crop'
+            else 'filer.thumbnail_processors.scale_and_crop_with_subject_location'
+            for processor in EasyThumbnailSettings.THUMBNAIL_PROCESSORS
+        ])
+
         # easy_thumbnails uses django's default storage backend (local file
         # system storage) by default, even if the DEFAULT_FILE_STORAGE setting
         # points to something else.


Test patch: