easy_thumbnails.source_generators: 21 total statements, 0.0% covered

Generated: Wed 2013-03-13 10:33 CET

Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/easy_thumbnails/source_generators.py

Stats: 0 executed, 16 missed, 5 excluded, 20 ignored

  1. try:
  2. from cStringIO import StringIO
  3. except ImportError:
  4. from StringIO import StringIO
  5. try:
  6. from PIL import Image
  7. except ImportError:
  8. import Image
  9. from easy_thumbnails import utils
  10. def pil_image(source, exif_orientation=True, **options):
  11. """
  12. Try to open the source file directly using PIL, ignoring any errors.
  13. exif_orientation
  14. If EXIF orientation data is present, perform any required reorientation
  15. before passing the data along the processing pipeline.
  16. """
  17. # Use a StringIO wrapper because if the source is an incomplete file like
  18. # object, PIL may have problems with it. For example, some image types
  19. # require tell and seek methods that are not present on all storage
  20. # File objects.
  21. if not source:
  22. return
  23. source = StringIO(source.read())
  24. try:
  25. image = Image.open(source)
  26. # Fully load the image now to catch any problems with the image
  27. # contents.
  28. image.load()
  29. except Exception:
  30. return
  31. if exif_orientation:
  32. image = utils.exif_orientation(image)
  33. return image