Home | Trees | Indices | Help |
|
---|
|
1 # copyright 2006-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. 2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr 3 # 4 # This file is part of logilab-mtconverter. 5 # 6 # logilab-mtconverter is free software: you can redistribute it and/or modify it 7 # under the terms of the GNU Lesser General Public License as published by the 8 # Free Software Foundation, either version 2.1 of the License, or (at your 9 # option) any later version. 10 # 11 # logilab-mtconverter is distributed in the hope that it will be useful, but 12 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License 14 # for more details. 15 # 16 # You should have received a copy of the GNU Lesser General Public License along 17 # with logilab-mtconverter. If not, see <http://www.gnu.org/licenses/>. 18 """PIL based transformations for images""" 19 20 from StringIO import StringIO 21 22 from PIL import Image 23 24 from logilab.mtconverter.transform import Transform 2527 28 format = None # override in subclasses (make pylint happy) 2942 43 49 55 61 67 73 79 85 86 transform_classes = [c for c in globals().values() 87 if isinstance(c, type) and issubclass(c, PILTransform) 88 and not c is PILTransform] 8931 newwidth = trdata.get('width', None) 32 newheight = trdata.get('height', None) 33 pilimg = Image.open(StringIO(trdata.data)) 34 if self.format in ['jpeg', 'ppm']: 35 pilimg.draft("RGB", pilimg.size) 36 pilimg = pilimg.convert("RGB") 37 if newwidth or newheight: 38 pilimg.thumbnail((newwidth, newheight), Image.ANTIALIAS) 39 stream = StringIO() 40 pilimg.save(stream, self.format) 41 return stream.getvalue()
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Mon Mar 14 19:07:58 2016 | http://epydoc.sourceforge.net |