Anonymous avatar Anonymous committed 526a022

Spec.process now only optionally saves the new image to disk

Comments (0)

Files changed (4)

src/imagekit/__init__.py

+"""
+
+Django ImageKit
+
+Author: Justin Driscoll <justin.driscoll@gmail.com>
+Version: 1.0
+
+"""
+from models import IKModel
+from specs import ImageSpec

src/imagekit/models.py

 from django.db import models
 from django.db.models.base import ModelBase
 from django.utils.translation import ugettext_lazy as _
+
 from imagekit.options import Options
 from imagekit import specs
 

src/imagekit/specs.py

         return getattr(cls, 'access_as', cls.__name__.lower())
         
     @classmethod
-    def create(cls, image, filename):
+    def process(cls, image, save_as=None):
         processed_image = image.copy()
         for proc in cls.processors:
             processed_image = proc.process(processed_image)
-        try:
-            if image.format != 'JPEG':
-                try:
-                    processed_image.save(im_filename)
-                    return
-                except KeyError:
-                    pass
-            processed_image.save(filename, 'JPEG',
-                                 quality=int(cls.output_quality),
-                                 optimize=True)
-        except IOError, e:
-            if os.path.isfile(filename):
-                os.unlink(filename)
-            raise e
+            
+        if save_as is not None:
+            try:
+                if image.format != 'JPEG':
+                    try:
+                        processed_image.save(save_as)
+                        return
+                    except KeyError:
+                        pass
+                processed_image.save(save_as, 'JPEG',
+                                     quality=int(cls.output_quality),
+                                     optimize=True)
+            except IOError, e:
+                if os.path.isfile(filename):
+                    os.unlink(filename)
+                raise e
+        
         return processed_image
         
 
         self.spec = spec
         
     def create(self):
-        self._img = self.spec.create(self.image, self.path)
+        self._img = self.spec.process(self.image, save_as=self.path)
         
     def delete(self):
         if self.exists:

src/imagekit/tests.py

 from django.core.files.base import ContentFile
 from django.test import TestCase
 
-from models import *
+from models import IKModel
+from specs import ImageSpec
 
 
 # Required PIL classes may or may not be available from the root namespace
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.