summary refs log tree commit diff
path: root/synapse/media
diff options
context:
space:
mode:
authorKegan Dougal <kegan@matrix.org>2015-01-06 11:43:04 +0000
committerKegan Dougal <kegan@matrix.org>2015-01-06 11:43:04 +0000
commit78edb47cc53e52504f2ceb8efa23ae1e50b66946 (patch)
tree339379ccd9089417c1349cc470e7bd4feb54eac7 /synapse/media
parentSYN-229: Include Content-Length when downloading files (diff)
downloadsynapse-78edb47cc53e52504f2ceb8efa23ae1e50b66946.tar.xz
SYN-208/SYN-228: Add runtime checks on startup to enforce that JPEG/PNG support is included when installing pillow.
Diffstat (limited to 'synapse/media')
-rw-r--r--synapse/media/v1/__init__.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/synapse/media/v1/__init__.py b/synapse/media/v1/__init__.py
index e69de29bb2..2b1762dcd8 100644
--- a/synapse/media/v1/__init__.py
+++ b/synapse/media/v1/__init__.py
@@ -0,0 +1,29 @@
+# -*- coding: utf-8 -*-
+import PIL.Image
+
+# check for JPEG support.
+try:
+    PIL.Image._getdecoder("rgb", "jpeg", None)
+except IOError as e:
+    if str(e).startswith("decoder jpeg not available"):
+        raise Exception(
+            "FATAL: jpeg codec not supported. Install pillow correctly! "
+            " 'sudo apt-get install libjpeg-dev' then 'pip install -I pillow'"
+        )
+except Exception:
+    # any other exception is fine
+    pass
+
+
+# check for PNG support.
+try:
+    PIL.Image._getdecoder("rgb", "zip", None)
+except IOError as e:
+    if str(e).startswith("decoder zip not available"):
+        raise Exception(
+            "FATAL: zip codec not supported. Install pillow correctly! "
+            " 'sudo apt-get install libjpeg-dev' then 'pip install -I pillow'"
+        )
+except Exception:
+    # any other exception is fine
+    pass
\ No newline at end of file