Beispiel #1
0
 def resize(self, size):
     size = tuple(int(s) for s in size.split('x'))
     idownloadable = self.entity.cw_adapt_to('IDownloadable')
     ctype = idownloadable.download_content_type()
     fmt = ctype and ctype.split('/', 1)[1] or None
     if fmt is None:
         self.error('unable to resize')
         raise UnResizeable
     data = idownloadable.download_data()
     pilimg = pilopen(Binary(data))
     pilimg.thumbnail(size, ANTIALIAS)
     stream = Binary()
     pilimg.save(stream, fmt)
     stream.seek(0)
     stream.filename = idownloadable.download_file_name()
     return stream
Beispiel #2
0
 def thumbnail(self, shadow=False, size=None):
     if size is None:
         size = self._cw.vreg.config['image-thumb-size']
     size = tuple(int(s) for s in size.split('x'))
     idownloadable = self.entity.cw_adapt_to('IDownloadable')
     data = idownloadable.download_data()
     try:
         pilimg = pilopen(Binary(data))
     except IOError:
         raise UnResizeable
     if shadow:
         self.warning('[1.15.0] the shadow parameter is now unused '
                      'and you should use css rules to lay shadows out',
                      DeprecationWarning)
     pilimg.thumbnail(size, ANTIALIAS)
     stream = Binary()
     pilimg.save(stream, 'png')
     stream.seek(0)
     ithumbnail = self.entity.cw_adapt_to('IThumbnail')
     stream.filename = ithumbnail.thumbnail_file_name()
     return stream