mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-17 11:41:11 +00:00
Add system check for libjpeg / zlib
This commit is contained in:
parent
16020af213
commit
a311955534
4 changed files with 60 additions and 0 deletions
|
|
@ -1,5 +1,7 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
from . import checks
|
||||
|
||||
|
||||
class WagtailImagesAppConfig(AppConfig):
|
||||
name = 'wagtail.wagtailimages'
|
||||
|
|
|
|||
BIN
wagtail/wagtailimages/check_files/wagtail.jpg
Normal file
BIN
wagtail/wagtailimages/check_files/wagtail.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.1 KiB |
BIN
wagtail/wagtailimages/check_files/wagtail.png
Normal file
BIN
wagtail/wagtailimages/check_files/wagtail.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 849 B |
58
wagtail/wagtailimages/checks.py
Normal file
58
wagtail/wagtailimages/checks.py
Normal file
|
|
@ -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
|
||||
Loading…
Reference in a new issue