<s> from io import BytesIO <EOL> from thumbnails . errors import ThumbnailError <EOL> from . base import BaseThumbnailEngine <EOL> class PillowEngine ( BaseThumbnailEngine ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( PillowEngine , self ) . __init__ ( ) <EOL> from PIL import Image , ImageFile <EOL> self . _Image = Image <EOL> self . _ImageFile = ImageFile <EOL> def engine_load_image ( self , original ) : <EOL> image = self . _Image . open ( BytesIO ( original . open ( ) . read ( ) ) ) <EOL> try : <EOL> image . load ( ) <EOL> except ( IOError , OSError ) as e : <EOL> raise ThumbnailError ( '<STR_LIT>' , exception = e ) <EOL> return image <EOL> def engine_raw_data ( self , image , options ) : <EOL> self . _ImageFile . MAXBLOCK = max ( self . _ImageFile . MAXBLOCK , int ( image . size [ <NUM_LIT:0> ] * image . size [ <NUM_LIT:1> ] ) ) <EOL> pillow_options = { <EOL> '<STR_LIT>' : self . get_format ( image , options ) , <EOL> '<STR_LIT>' : options [ '<STR_LIT>' ] , <EOL> } <EOL> _file = BytesIO ( ) <EOL> image . save ( _file , ** pillow_options ) <EOL> return _file . getvalue ( ) <EOL> def engine_image_size ( self , image ) : <EOL> return image . size <EOL> def engine_scale ( self , image , width , height ) : <EOL> return image . resize ( ( width , height ) , resample = self . _Image . ANTIALIAS ) <EOL> def engine_crop ( self , image , size , crop , options ) : <EOL> x , y = crop <EOL> width , height = size <EOL> return image . crop ( ( x , y , x + width , y + height ) ) <EOL> def engine_cleanup ( self , original ) : <EOL> pass <EOL> def engine_colormode ( self , image , colormode ) : <EOL> if colormode == '<STR_LIT>' or colormode == '<STR_LIT>' : <EOL> if image . mode == '<STR_LIT>' : <EOL> return image <EOL> if image . mode == '<STR_LIT>' : <EOL> return image . convert ( '<STR_LIT>' ) <EOL> return image . convert ( colormode ) <EOL> if colormode == '<STR_LIT>' : <EOL> return image . convert ( '<STR_LIT:L>' ) <EOL> return image . convert ( colormode ) <EOL> def engine_get_format ( self , image ) : <EOL> return image . format </s>
