Commits

Joseph Tate committed 6d48e70

Better handling of PIL imports

Comments (0)

Files changed (1)

tw2/upload/model/image.py

         '''Implement special post processing in this method'''
 
 try:
-    import PIL.Image
+    import Image
 except ImportError:
-    has_PIL = False
+    try:
+        import PIL.Image as Image
+    except ImportError:
+        has_PIL = False
+    else:
+        has_PIL = True
 else:
     has_PIL = True
 
         if not has_PIL:
             raise NotImplementedError('Cannot call crop without having PIL installed')
         if x2 > x1 and y2 > y1:
-            img = PIL.Image.open(self.fs_path)
+            img = Image.open(self.fs_path)
             cropped = img.crop((x1, y1, x2, y2))
 
             for extname, extent in self.extents.iteritems():
-                res = cropped.resize(extent, PIL.Image.ANTIALIAS)
+                res = cropped.resize(extent, Image.ANTIALIAS)
                 filen = self._fs_file(self._extent_basename(extname), create=True)
                 res.save(filen)
                 os.chmod(filen, self.mode)
     def default_crop(self):
         if not has_PIL:
             raise NotImplementedError('Cannot call crop without having PIL installed')
-        img = PIL.Image.open(self.fs_path)
+        img = Image.open(self.fs_path)
         w, h = img.size
         x1, y1, x2, y2 = self.crop_region(w,h)
         if self.crop(x1, y1, x2, y2):