diff --git a/wagtail/wagtailimages/apps.py b/wagtail/wagtailimages/apps.py index 88cd6e3f0..3b5a61900 100644 --- a/wagtail/wagtailimages/apps.py +++ b/wagtail/wagtailimages/apps.py @@ -1,5 +1,7 @@ from django.apps import AppConfig +from . import checks + class WagtailImagesAppConfig(AppConfig): name = 'wagtail.wagtailimages' diff --git a/wagtail/wagtailimages/check_files/wagtail.jpg b/wagtail/wagtailimages/check_files/wagtail.jpg new file mode 100644 index 000000000..58d26fba2 Binary files /dev/null and b/wagtail/wagtailimages/check_files/wagtail.jpg differ diff --git a/wagtail/wagtailimages/check_files/wagtail.png b/wagtail/wagtailimages/check_files/wagtail.png new file mode 100644 index 000000000..0597e9d90 Binary files /dev/null and b/wagtail/wagtailimages/check_files/wagtail.png differ diff --git a/wagtail/wagtailimages/checks.py b/wagtail/wagtailimages/checks.py new file mode 100644 index 000000000..c4aafcf22 --- /dev/null +++ b/wagtail/wagtailimages/checks.py @@ -0,0 +1,58 @@ +import os + +from django.core.checks import register, Warning + +from willow.image import Image + + +def has_jpeg_support(): + wagtail_jpg = os.path.join(os.path.dirname(__file__), 'check_files', 'wagtail.jpg') + is_ok = True + f = open(wagtail_jpg, 'rb') + + try: + Image.open(f) + except (IOError, Image.LoaderError): + is_ok = False + finally: + f.close() + + return is_ok + + +def has_png_support(): + wagtail_png = os.path.join(os.path.dirname(__file__), 'check_files', 'wagtail.png') + is_ok = True + f = open(wagtail_png, 'rb') + + try: + Image.open(f) + except (IOError, Image.LoaderError): + is_ok = False + finally: + f.close() + + return is_ok + + +@register() +def image_library_check(app_configs, **kwargs): + errors = [] + + if not has_jpeg_support(): + errors.append( + Warning( + 'JPEG image support is not available', + hint="Check that the 'libjpeg' library is installed, then reinstall Pillow." + ) + ) + + if not has_png_support(): + errors.append( + Warning( + 'PNG image support is not available', + hint="Check that the 'zlib' library is installed, then reinstall Pillow." + ) + ) + + return errors