Re: [Zope] Generating thumbnails on the fly using PIL
From: "Pieter Claerhout" <Pieter_Claerhout@CreoScitex.com>
Hope that somebody can help with this.
Well, you can look at the attached product, it is an subclass of Image that has thumbnails. Actually, if you remove EasyResourcse and EasyDublinCore from the constructor of the product, it should work in a standard Zope environment. The code that does the resizing is this part: def makeimage(self, maxx=0, maxy=0, ratio=1, ftype='JPEG'): """Creates an image from the orginal with specified size.""" if self.orig_data == None: tmpdata = self.data else: tmpdata = self.orig_data file = StringIO(str(tmpdata)) if maxx <> 0 and maxy <> 0: im = PIL.Image.open(file) if ratio==1: # keep aspect-ratio aspectx = float(im.size[0]) / float(maxx) aspecty = float(im.size[1]) / float(maxy) if aspectx > aspecty: maxy = float(im.size[1]) / aspectx if aspectx < aspecty: maxx = float(im.size[0]) / aspecty maxx = int(maxx) maxy = int(maxy) if im.mode!='RGB' and im.mode!='CMYK': im = im.convert("RGB") im.load() im = im.resize((maxx, maxy), PIL.Image.BICUBIC) newfile = StringIO() im.save(newfile, ftype, optimize=1) return newfile.getvalue(), TYPEINFOMAP[ftype]['content_type'], im.size[0], im.size[1] return None, '', 0, 0 Hope it helps.
participants (1)
-
Lennart Regebro