Justin Driscoll avatar Justin Driscoll committed 120f9bb

Cleaned up trailing whitespace

Comments (0)

Files changed (7)

imagekit/defaults.py

 
 from imagekit.specs import ImageSpec
 from imagekit import processors
-    
+
 class ResizeThumbnail(processors.Resize):
     width = 100
     height = 50
     crop = True
-    
+
 class EnhanceSmall(processors.Adjustment):
     contrast = 1.2
     sharpness = 1.1
-    
+
 class SampleReflection(processors.Reflection):
     size = 0.5
     background_color = "#000000"
 class PNGFormat(processors.Format):
     format = 'PNG'
     extension = 'png'
-    
+
 class DjangoAdminThumbnail(ImageSpec):
     access_as = 'admin_thumbnail'
     processors = [ResizeThumbnail, EnhanceSmall, SampleReflection, PNGFormat]
         from PIL import ImageEnhance
         from PIL import ImageColor
     except ImportError:
-        raise ImportError('ImageKit was unable to import the Python Imaging Library. Please confirm it`s installed and available on your current Python path.')
+        raise ImportError('ImageKit was unable to import the Python Imaging Library. Please confirm it`s installed and available on your current Python path.')

imagekit/models.py

 
 class ImageModelBase(ModelBase):
     """ ImageModel metaclass
-    
+
     This metaclass parses IKOptions and loads the specified specification
     module.
-    
+
     """
     def __init__(cls, name, bases, attrs):
         parents = [b for b in bases if isinstance(b, ImageModelBase)]
             module = __import__(opts.spec_module,  {}, {}, [''])
         except ImportError:
             raise ImportError('Unable to load imagekit config module: %s' % \
-                opts.spec_module)    
+                opts.spec_module)
         for spec in [spec for spec in module.__dict__.values() \
                      if isinstance(spec, type) \
                      and issubclass(spec, specs.ImageSpec) \
 
 class ImageModel(models.Model):
     """ Abstract base class implementing all core ImageKit functionality
-    
+
     Subclasses of ImageModel are augmented with accessors for each defined
     image specification and can override the inner IKOptions class to customize
     storage locations and other options.
-    
+
     """
     __metaclass__ = ImageModelBase
 
     class Meta:
         abstract = True
-        
+
     class IKOptions:
         pass
-        
+
     def admin_thumbnail_view(self):
         if not self._imgfield:
             return None
                     (escape(self._imgfield.url), escape(prop.url))
     admin_thumbnail_view.short_description = _('Thumbnail')
     admin_thumbnail_view.allow_tags = True
-    
+
     @property
     def _imgfield(self):
         return getattr(self, self._ik.image_field)
-    
+
     @property
     def _storage(self):
         return getattr(self._ik, 'storage', self._imgfield.storage)
             if spec.pre_cache:
                 prop = getattr(self, spec.name())
                 prop._create()
-                
+
     def save_image(self, name, image, save=True, replace=True):
         if self._imgfield and replace:
             self._imgfield.delete(save=False)

imagekit/options.py

 # Imagekit options
 from imagekit import processors
 from imagekit.specs import ImageSpec
-    
+
 
 class Options(object):
     """ Class handling per-model imagekit options
     admin_thumbnail_spec = 'admin_thumbnail'
     spec_module = 'imagekit.defaults'
     #storage = defaults to image_field.storage
-    
-    def __init__(self, opts):        
+
+    def __init__(self, opts):
         for key, value in opts.__dict__.iteritems():
             setattr(self, key, value)
             self.specs = []

imagekit/processors.py

 """ Imagekit Image "ImageProcessors"
 
-A processor defines a set of class variables (optional) and a 
+A processor defines a set of class variables (optional) and a
 class method named "process" which processes the supplied image using
 the class properties as settings. The process method can be overridden as well allowing user to define their
 own effects/processes entirely.
 
 class ImageProcessor(object):
     """ Base image processor class """
-            
+
     @classmethod
     def process(cls, img, fmt, obj):
         return img, fmt
-        
+
 
 class Adjustment(ImageProcessor):
     color = 1.0
 class Format(ImageProcessor):
     format = 'JPEG'
     extension = 'jpg'
-    
+
     @classmethod
     def process(cls, img, fmt, obj):
         return img, cls.format
     background_color = '#FFFFFF'
     size = 0.0
     opacity = 0.6
-    
+
     @classmethod
     def process(cls, img, fmt, obj):
         # convert bgcolor string to rgb value
     height = None
     crop = False
     upscale = False
-    
+
     @classmethod
     def process(cls, img, fmt, obj):
         cur_width, cur_height = img.size
             img = img.resize(new_dimensions, Image.ANTIALIAS)
         return img, fmt
 
-    
+
 class Transpose(ImageProcessor):
     """ Rotates or flips the image
-    
+
     Method should be one of the following strings:
         - FLIP_LEFT RIGHT
         - FLIP_TOP_BOTTOM
         - ROTATE_270
         - ROTATE_180
         - auto
-        
+
     If method is set to 'auto' the processor will attempt to rotate the image
     according to the EXIF Orientation data.
-        
+
     """
     EXIF_ORIENTATION_STEPS = {
         1: [],
         7: ['ROTATE_90', 'FLIP_LEFT_RIGHT'],
         8: ['ROTATE_90'],
     }
-    
+
     method = 'auto'
-    
+
     @classmethod
     def process(cls, img, fmt, obj):
         if cls.method == 'auto':

imagekit/specs.py

     quality = 70
     increment_count = False
     processors = []
-    
+
     @classmethod
     def name(cls):
         return getattr(cls, 'access_as', cls.__name__.lower())
-        
+
     @classmethod
     def process(cls, image, obj):
         fmt = image.format
             img, fmt = proc.process(img, fmt, obj)
         img.format = fmt
         return img, fmt
-        
+
 
 class Accessor(object):
     def __init__(self, obj, spec):
         self._fmt = None
         self._obj = obj
         self.spec = spec
-        
+
     def _get_imgfile(self):
         format = self._img.format or 'JPEG'
         if format != 'JPEG':
                                   quality=int(self.spec.quality),
                                   optimize=True)
         return imgfile
-        
+
     def _create(self):
         if self._exists():
             return
         try:
             fp = self._obj._imgfield.storage.open(self._obj._imgfield.name)
         except IOError:
-            return            
+            return
         fp.seek(0)
         fp = StringIO(fp.read())
         self._img, self._fmt = self.spec.process(Image.open(fp), self._obj)
         # save the new image to the cache
         content = ContentFile(self._get_imgfile().read())
         self._obj._storage.save(self.name, content)
-        
+
     def _delete(self):
         self._obj._storage.delete(self.name)
 
                 setattr(self._obj, fieldname, current_count + 1)
                 self._obj.save(clear_cache=False)
         return self._obj._storage.url(self.name)
-        
+
     @property
     def file(self):
         self._create()
         return self._obj._storage.open(self.name)
-        
+
     @property
     def image(self):
         if self._img is None:
             if self._img is None:
                 self._img = Image.open(self.file)
         return self._img
-        
+
     @property
     def width(self):
         return self.image.size[0]
-        
+
     @property
     def height(self):
         return self.image.size[1]

imagekit/tests.py

 
 class ResizeToWidth(processors.Resize):
     width = 100
-    
+
 class ResizeToHeight(processors.Resize):
     height = 100
-    
+
 class ResizeToFit(processors.Resize):
     width = 100
     height = 100
-    
+
 class ResizeCropped(ResizeToFit):
     crop = ('center', 'center')
 
 class TestResizeToHeight(ImageSpec):
     access_as = 'to_height'
     processors = [ResizeToHeight]
-    
+
 class TestResizeCropped(ImageSpec):
     access_as = 'cropped'
     processors = [ResizeCropped]
 class TestPhoto(ImageModel):
     """ Minimal ImageModel class for testing """
     image = models.ImageField(upload_to='images')
-    
+
     class IKOptions:
         spec_module = 'imagekit.tests'
-    
+
 
 class IKTest(TestCase):
     """ Base TestCase class """
         Image.new('RGB', (800, 600)).save(tmp, 'JPEG')
         tmp.seek(0)
         return tmp
-        
+
     def setUp(self):
         self.p = TestPhoto()
         img = self.generate_image()
         self.p.save_image('test.jpeg', ContentFile(img.read()))
         self.p.save()
         img.close()
-        
+
     def test_save_image(self):
         img = self.generate_image()
         path = self.p.image.path
         self.p.save_image('test.jpeg', ContentFile(img.read()))
         self.failIf(os.path.isfile(path))
         img.close()
-        
+
     def test_setup(self):
         self.assertEqual(self.p.image.width, 800)
         self.assertEqual(self.p.image.height, 600)
-        
+
     def test_to_width(self):
         self.assertEqual(self.p.to_width.width, 100)
         self.assertEqual(self.p.to_width.height, 75)
-        
+
     def test_to_height(self):
         self.assertEqual(self.p.to_height.width, 133)
         self.assertEqual(self.p.to_height.height, 100)
-        
+
     def test_crop(self):
         self.assertEqual(self.p.cropped.width, 100)
         self.assertEqual(self.p.cropped.height, 100)
         tup = (settings.MEDIA_URL, self.p._ik.cache_dir,
                'images/test_to_width.jpeg')
         self.assertEqual(self.p.to_width.url, "%s%s/%s" % tup)
- 
+
     def tearDown(self):
         # make sure image file is deleted
         path = self.p.image.path
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.