[Checkins] SVN: z3c.image/trunk/src/z3c/image/ fix png and gif
handling and added tests
Bernd Dorn
bernd.dorn at fhv.at
Mon Oct 30 19:10:49 EST 2006
Log message for revision 71000:
fix png and gif handling and added tests
Changed:
U z3c.image/trunk/src/z3c/image/proc/README.txt
U z3c.image/trunk/src/z3c/image/proc/adapter.py
A z3c.image/trunk/src/z3c/image/testing/data/hiring.gif
A z3c.image/trunk/src/z3c/image/testing/data/locked.png
-=-
Modified: z3c.image/trunk/src/z3c/image/proc/README.txt
===================================================================
--- z3c.image/trunk/src/z3c/image/proc/README.txt 2006-10-30 18:14:15 UTC (rev 70999)
+++ z3c.image/trunk/src/z3c/image/proc/README.txt 2006-10-31 00:10:44 UTC (rev 71000)
@@ -54,3 +54,28 @@
>>> res.getImageSize()
(30, 20)
+Also the PNG and GIF filetypes are supported.
+
+ >>> image = testing.getTestImage('locked.png')
+ >>> image.contentType
+ 'image/png'
+ >>> image.getImageSize()
+ (128, 128)
+ >>> pimg = IProcessableImage(image)
+ >>> pimg.resize([80,80])
+ >>> res = pimg.process()
+ >>> res.getImageSize()
+ (80, 80)
+
+ >>> image = testing.getTestImage('hiring.gif')
+ >>> image.contentType
+ 'image/gif'
+ >>> image.getImageSize()
+ (199, 183)
+ >>> pimg = IProcessableImage(image)
+ >>> pimg.resize([80,80])
+ >>> res = pimg.process()
+ >>> res.getImageSize()
+ (80, 80)
+
+
Modified: z3c.image/trunk/src/z3c/image/proc/adapter.py
===================================================================
--- z3c.image/trunk/src/z3c/image/proc/adapter.py 2006-10-30 18:14:15 UTC (rev 70999)
+++ z3c.image/trunk/src/z3c/image/proc/adapter.py 2006-10-31 00:10:44 UTC (rev 71000)
@@ -38,26 +38,18 @@
def getPILImg(self):
data = self.context.data
- # only make it a buffer if we need to, so we can handle
- # efficient files, like from z3c.extfile
- p = ImageFile.Parser()
- if type(data)==StringType:
- p.feed(data)
- else:
+ if type(data)!=StringType:
data.seek(0)
- while 1:
- s = data.read(1024)
- if not s:
- try:
- data.close()
- except:
- pass
- break
- p.feed(s)
- return p.close()
+ data = data.read()
+ p = Image.open(StringIO(data))
+ return p
def _toImage(self, pimg, *args,**kw):
"""returns an Image object from the given PIL image"""
+ if self.format == 'gif':
+ # optimization seems to create corrupted gif files wiht
+ # PIL, so we switch it off
+ kw.pop('optimize')
img = VImage(contentType=self.context.contentType,
size=pimg.size)
try:
@@ -94,6 +86,7 @@
img.data.seek(0)
return img
pimg = self.getPILImg()
+
for name,args,kwords in self.cmds:
func = getattr(pimg,name)
pimg = func(*args,**kwords)
Added: z3c.image/trunk/src/z3c/image/testing/data/hiring.gif
===================================================================
(Binary files differ)
Property changes on: z3c.image/trunk/src/z3c/image/testing/data/hiring.gif
___________________________________________________________________
Name: svn:mime-type
+ image/gif
Added: z3c.image/trunk/src/z3c/image/testing/data/locked.png
===================================================================
(Binary files differ)
Property changes on: z3c.image/trunk/src/z3c/image/testing/data/locked.png
___________________________________________________________________
Name: svn:mime-type
+ image/png
More information about the Checkins
mailing list