Commits

Anonymous committed 1404527

Renamed config_module to spec_module

  • Participants
  • Parent commits a1ea49a

Comments (0)

Files changed (3)

File src/imagekit/models.py

         user_opts = getattr(cls, 'IKConfig', None)
         opts = Options(user_opts)
         try:
-            module = __import__(opts.config_module,  {}, {}, [''])
+            module = __import__(opts.spec_module,  {}, {}, [''])
         except ImportError:
             raise ImportError('Unable to load imagekit config module: %s' % \
-                opts.config_module)    
+                opts.spec_module)    
         for spec in [spec for spec in module.__dict__.values() \
                      if isinstance(spec, type) \
                      and issubclass(spec, specs.ImageSpec) \

File src/imagekit/options.py

     cache_dir = 'images'
     save_count_as = None
     cache_filename_format = "%(filename)s_%(specname)s.%(extension)s"
-    config_module = 'imagekit.config'
+    spec_module = 'imagekit.config'
     
     def __init__(self, opts):        
         for key, value in opts.__dict__.iteritems():

File src/imagekit/processors.py

         return image
 
 
+class Adjustment(ImageProcessor):
+    color = 1.0
+    brightness = 1.0
+    contrast = 1.0
+    sharpness = 1.0
+
+    @classmethod
+    def process(cls, image, obj=None):
+        for name in ['Color', 'Brightness', 'Contrast', 'Sharpness']:
+            factor = getattr(cls, name.lower())
+            if factor != 1.0:
+                image = getattr(ImageEnhance, name)(image).enhance(factor)
+        return image
+
+
+class Reflection(ImageProcessor):
+    background_color = '#FFFFFF'
+    size = 0.0
+    opacity = 0.6
+    
+    @classmethod
+    def process(cls, image, obj=None):
+        # convert bgcolor string to rgb value
+        background_color = ImageColor.getrgb(cls.background_color)
+        # copy orignial image and flip the orientation
+        reflection = image.copy().transpose(Image.FLIP_TOP_BOTTOM)
+        # create a new image filled with the bgcolor the same size
+        background = Image.new("RGB", image.size, background_color)
+        # calculate our alpha mask
+        start = int(255 - (255 * cls.opacity)) # The start of our gradient
+        steps = int(255 * cls.size) # the number of intermedite values
+        increment = (255 - start) / float(steps)
+        mask = Image.new('L', (1, 255))
+        for y in range(255):
+            if y < steps:
+                val = int(y * increment + start)
+            else:
+                val = 255
+            mask.putpixel((0, y), val)
+        alpha_mask = mask.resize(image.size)
+        # merge the reflection onto our background color using the alpha mask
+        reflection = Image.composite(background, reflection, alpha_mask)
+        # crop the reflection
+        reflection_height = int(image.size[1] * cls.size)
+        reflection = reflection.crop((0, 0, image.size[0], reflection_height))
+        # create new image sized to hold both the original image and the reflection
+        composite = Image.new("RGB", (image.size[0], image.size[1]+reflection_height), background_color)
+        # paste the orignal image and the reflection into the composite image
+        composite.paste(image, (0, 0))
+        composite.paste(reflection, (0, image.size[1]))
+        # return the image complete with reflection effect
+        return composite
+
+
 class Resize(ImageProcessor):
     width = None
     height = None
 class Transpose(ImageProcessor):
     """ Rotates or flips the image
     
-    Method choices:
+    Method should be one of the following strings:
         - FLIP_LEFT RIGHT
         - FLIP_TOP_BOTTOM
         - ROTATE_90
     
     @classmethod
     def process(cls, image, obj=None):
-        return image.transpose(getattr(Image, cls.method))        
-
-    
-class Adjustment(ImageProcessor):
-    color = 1.0
-    brightness = 1.0
-    contrast = 1.0
-    sharpness = 1.0
-
-    @classmethod
-    def process(cls, image, obj=None):
-        for name in ['Color', 'Brightness', 'Contrast', 'Sharpness']:
-            factor = getattr(cls, name.lower())
-            if factor != 1.0:
-                image = getattr(ImageEnhance, name)(image).enhance(factor)
-        return image
-
-
-class Reflection(ImageProcessor):
-    background_color = '#FFFFFF'
-    size = 0.0
-    opacity = 0.6
-    
-    @classmethod
-    def process(cls, image, obj=None):
-        # convert bgcolor string to rgb value
-        background_color = ImageColor.getrgb(cls.background_color)
-        # copy orignial image and flip the orientation
-        reflection = image.copy().transpose(Image.FLIP_TOP_BOTTOM)
-        # create a new image filled with the bgcolor the same size
-        background = Image.new("RGB", image.size, background_color)
-        # calculate our alpha mask
-        start = int(255 - (255 * cls.opacity)) # The start of our gradient
-        steps = int(255 * cls.size) # the number of intermedite values
-        increment = (255 - start) / float(steps)
-        mask = Image.new('L', (1, 255))
-        for y in range(255):
-            if y < steps:
-                val = int(y * increment + start)
-            else:
-                val = 255
-            mask.putpixel((0, y), val)
-        alpha_mask = mask.resize(image.size)
-        # merge the reflection onto our background color using the alpha mask
-        reflection = Image.composite(background, reflection, alpha_mask)
-        # crop the reflection
-        reflection_height = int(image.size[1] * cls.size)
-        reflection = reflection.crop((0, 0, image.size[0], reflection_height))
-        # create new image sized to hold both the original image and the reflection
-        composite = Image.new("RGB", (image.size[0], image.size[1]+reflection_height), background_color)
-        # paste the orignal image and the reflection into the composite image
-        composite.paste(image, (0, 0))
-        composite.paste(reflection, (0, image.size[1]))
-        # return the image complete with reflection effect
-        return composite
+        return image.transpose(getattr(Image, cls.method))