__init__.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014-2016 OpenMarket Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import PIL.Image
  16. # check for JPEG support.
  17. try:
  18. PIL.Image._getdecoder("rgb", "jpeg", None)
  19. except IOError as e:
  20. if str(e).startswith("decoder jpeg not available"):
  21. raise Exception(
  22. "FATAL: jpeg codec not supported. Install pillow correctly! "
  23. " 'sudo apt-get install libjpeg-dev' then 'pip uninstall pillow &&"
  24. " pip install pillow --user'"
  25. )
  26. except Exception:
  27. # any other exception is fine
  28. pass
  29. # check for PNG support.
  30. try:
  31. PIL.Image._getdecoder("rgb", "zip", None)
  32. except IOError as e:
  33. if str(e).startswith("decoder zip not available"):
  34. raise Exception(
  35. "FATAL: zip codec not supported. Install pillow correctly! "
  36. " 'sudo apt-get install libjpeg-dev' then 'pip uninstall pillow &&"
  37. " pip install pillow --user'"
  38. )
  39. except Exception:
  40. # any other exception is fine
  41. pass