[Checkins] SVN: z3c.image/trunk/src/z3c/image/proc/ make adapter work with IFile and with file like data attr

Bernd Dorn bernd.dorn at fhv.at
Thu Aug 17 14:33:32 EDT 2006


Log message for revision 69618:
  make adapter work with IFile and with file like data attr

Changed:
  U   z3c.image/trunk/src/z3c/image/proc/adapter.py
  U   z3c.image/trunk/src/z3c/image/proc/browser.py

-=-
Modified: z3c.image/trunk/src/z3c/image/proc/adapter.py
===================================================================
--- z3c.image/trunk/src/z3c/image/proc/adapter.py	2006-08-17 18:31:01 UTC (rev 69617)
+++ z3c.image/trunk/src/z3c/image/proc/adapter.py	2006-08-17 18:33:31 UTC (rev 69618)
@@ -1,18 +1,20 @@
 from zope.interface import implements
 from zope import component
 from zope.app.file import Image
-from zope.app.file.interfaces import IImage
+from zope.app.file.interfaces import IFile
 from zope.cachedescriptors.property import readproperty
 from PIL import Image as PILImage
 from cStringIO import StringIO
 from interfaces import IProcessableImage
 from PIL import ImageFile
+from types import StringType
+
 # see http://mail.python.org/pipermail/image-sig/2003-May/002228.html
 ImageFile.MAXBLOCK = 1024*1024
 
 class ProcessableImage(object):
 
-    component.adapts(IImage)
+    component.adapts(IFile)
     implements(IProcessableImage)
 
     def __init__(self,image):
@@ -22,7 +24,12 @@
 
     @readproperty
     def pimg(self):
-        return PILImage.open(StringIO(self.context.data))
+        data = self.context.data
+        # only make it a buffer if we need to, so we can handle
+        # efficient files, like from z3c.extfile
+        if type(data)==StringType:
+            data = StringIO(data)
+        return PILImage.open(data)
         
     def _toImage(self,*args,**kw):
         """returns an Image object from the given PIL image"""

Modified: z3c.image/trunk/src/z3c/image/proc/browser.py
===================================================================
--- z3c.image/trunk/src/z3c/image/proc/browser.py	2006-08-17 18:31:01 UTC (rev 69617)
+++ z3c.image/trunk/src/z3c/image/proc/browser.py	2006-08-17 18:33:31 UTC (rev 69618)
@@ -6,6 +6,7 @@
 import zope.datetime 
 import time
 from datetime import datetime
+from zope.app.file.image import getImageInfo
 
 def _getNewSize(image_size, desired_size, keep_aspect):
     """Resizes image_size to desired_size, optionally keeping the
@@ -96,7 +97,8 @@
 
     def __init__(self,context,request):
         super(ResizedImageView,self).__init__(context,request)
-        self.size = self.context.getImageSize()
+        t,w,h = getImageInfo(self.context.data)
+        self.size = (w,h)
         self.width = self.request.form.get('w',self.size[0])
         self.height = self.request.form.get('h',self.size[1])
 



More information about the Checkins mailing list