<s> """<STR_LIT>""" <EOL> import datetime <EOL> import logging <EOL> import re <EOL> import time <EOL> import StringIO <EOL> try : <EOL> import json as simplejson <EOL> except ImportError : <EOL> import simplejson <EOL> try : <EOL> import PIL <EOL> from PIL import _imaging <EOL> from PIL import Image <EOL> except ImportError : <EOL> import _imaging <EOL> try : <EOL> import Image <EOL> except ImportError : <EOL> from PIL import Image <EOL> from google . appengine . api import apiproxy_stub <EOL> from google . appengine . api import apiproxy_stub_map <EOL> from google . appengine . api import blobstore <EOL> from google . appengine . api import datastore <EOL> from google . appengine . api import datastore_errors <EOL> from google . appengine . api import datastore_types <EOL> from google . appengine . api import images <EOL> from google . appengine . api . images import images_blob_stub <EOL> from google . appengine . api . images import images_service_pb <EOL> from google . appengine . runtime import apiproxy_errors <EOL> GS_INFO_KIND = "<STR_LIT>" <EOL> BLOB_SERVING_URL_KIND = images_blob_stub . BLOB_SERVING_URL_KIND <EOL> MAX_REQUEST_SIZE = <NUM_LIT:32> << <NUM_LIT:20> <EOL> _EXIF_ORIENTATION_TAG = <NUM_LIT> <EOL> _EXIF_DATETIMEORIGINAL_TAG = <NUM_LIT> <EOL> _EXIF_TAGS = { <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> _EXIF_ORIENTATION_TAG : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> _EXIF_DATETIMEORIGINAL_TAG : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" , <EOL> <NUM_LIT> : "<STR_LIT>" } <EOL> def _ArgbToRgbaTuple ( argb ) : <EOL> """<STR_LIT>""" <EOL> unsigned_argb = argb % <NUM_LIT> <EOL> return ( ( unsigned_argb >> <NUM_LIT:16> ) & <NUM_LIT> , <EOL> ( unsigned_argb >> <NUM_LIT:8> ) & <NUM_LIT> , <EOL> unsigned_argb & <NUM_LIT> , <EOL> ( unsigned_argb >> <NUM_LIT> ) & <NUM_LIT> ) <EOL> def _BackendPremultiplication ( color ) : <EOL> """<STR_LIT>""" <EOL> alpha = color [ <NUM_LIT:3> ] <EOL> rgb = color [ <NUM_LIT:0> : <NUM_LIT:3> ] <EOL> multiplied = [ ( x * ( alpha + <NUM_LIT:1> ) ) >> <NUM_LIT:8> for x in rgb ] <EOL> if alpha : <EOL> alpha_inverse = <NUM_LIT> / alpha <EOL> unmultiplied = [ ( x * alpha_inverse ) >> <NUM_LIT:16> for x in multiplied ] <EOL> else : <EOL> unmultiplied = [ <NUM_LIT:0> ] * <NUM_LIT:3> <EOL> return tuple ( unmultiplied + [ alpha ] ) <EOL> class ImagesServiceStub ( apiproxy_stub . APIProxyStub ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , service_name = "<STR_LIT>" , host_prefix = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> super ( ImagesServiceStub , self ) . __init__ ( service_name , <EOL> max_request_size = MAX_REQUEST_SIZE ) <EOL> self . _blob_stub = images_blob_stub . ImagesBlobStub ( host_prefix ) <EOL> Image . init ( ) <EOL> def _Dynamic_Composite ( self , request , response ) : <EOL> """<STR_LIT>""" <EOL> width = request . canvas ( ) . width ( ) <EOL> height = request . canvas ( ) . height ( ) <EOL> color = _ArgbToRgbaTuple ( request . canvas ( ) . color ( ) ) <EOL> color = _BackendPremultiplication ( color ) <EOL> canvas = Image . new ( "<STR_LIT>" , ( width , height ) , color ) <EOL> sources = [ ] <EOL> if ( not request . canvas ( ) . width ( ) or request . canvas ( ) . width ( ) > <NUM_LIT> or <EOL> not request . canvas ( ) . height ( ) or request . canvas ( ) . height ( ) > <NUM_LIT> ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> if not request . image_size ( ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> if not request . options_size ( ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> if request . options_size ( ) > images . MAX_COMPOSITES_PER_REQUEST : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> for image in request . image_list ( ) : <EOL> sources . append ( self . _OpenImageData ( image ) ) <EOL> for options in request . options_list ( ) : <EOL> if ( options . anchor ( ) < images . TOP_LEFT or <EOL> options . anchor ( ) > images . BOTTOM_RIGHT ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> if options . source_index ( ) >= len ( sources ) or options . source_index ( ) < <NUM_LIT:0> : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> if options . opacity ( ) < <NUM_LIT:0> or options . opacity ( ) > <NUM_LIT:1> : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> source = sources [ options . source_index ( ) ] <EOL> x_anchor = ( options . anchor ( ) % <NUM_LIT:3> ) * <NUM_LIT:0.5> <EOL> y_anchor = ( options . anchor ( ) / <NUM_LIT:3> ) * <NUM_LIT:0.5> <EOL> x_offset = int ( options . x_offset ( ) + x_anchor * ( width - source . size [ <NUM_LIT:0> ] ) ) <EOL> y_offset = int ( options . y_offset ( ) + y_anchor * ( height - source . size [ <NUM_LIT:1> ] ) ) <EOL> if source . mode == "<STR_LIT>" : <EOL> canvas . paste ( source , ( x_offset , y_offset ) , source ) <EOL> else : <EOL> alpha = options . opacity ( ) * <NUM_LIT:255> <EOL> mask = Image . new ( "<STR_LIT:L>" , source . size , alpha ) <EOL> canvas . paste ( source , ( x_offset , y_offset ) , mask ) <EOL> response_value = self . _EncodeImage ( canvas , request . canvas ( ) . output ( ) ) <EOL> response . mutable_image ( ) . set_content ( response_value ) <EOL> def _Dynamic_Histogram ( self , request , response ) : <EOL> """<STR_LIT>""" <EOL> image = self . _OpenImageData ( request . image ( ) ) <EOL> img_format = image . format <EOL> if img_format not in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . NOT_IMAGE ) <EOL> image = image . convert ( "<STR_LIT>" ) <EOL> red = [ <NUM_LIT:0> ] * <NUM_LIT> <EOL> green = [ <NUM_LIT:0> ] * <NUM_LIT> <EOL> blue = [ <NUM_LIT:0> ] * <NUM_LIT> <EOL> for pixel in image . getdata ( ) : <EOL> red [ int ( ( pixel [ <NUM_LIT:0> ] * pixel [ <NUM_LIT:3> ] ) / <NUM_LIT:255> ) ] += <NUM_LIT:1> <EOL> green [ int ( ( pixel [ <NUM_LIT:1> ] * pixel [ <NUM_LIT:3> ] ) / <NUM_LIT:255> ) ] += <NUM_LIT:1> <EOL> blue [ int ( ( pixel [ <NUM_LIT:2> ] * pixel [ <NUM_LIT:3> ] ) / <NUM_LIT:255> ) ] += <NUM_LIT:1> <EOL> histogram = response . mutable_histogram ( ) <EOL> for value in red : <EOL> histogram . add_red ( value ) <EOL> for value in green : <EOL> histogram . add_green ( value ) <EOL> for value in blue : <EOL> histogram . add_blue ( value ) <EOL> def _Dynamic_Transform ( self , request , response ) : <EOL> """<STR_LIT>""" <EOL> original_image = self . _OpenImageData ( request . image ( ) ) <EOL> input_settings = request . input ( ) <EOL> correct_orientation = ( <EOL> input_settings . has_correct_exif_orientation ( ) and <EOL> input_settings . correct_exif_orientation ( ) == <EOL> images_service_pb . InputSettings . CORRECT_ORIENTATION ) <EOL> source_metadata = self . _ExtractMetadata ( <EOL> original_image , input_settings . parse_metadata ( ) ) <EOL> if input_settings . parse_metadata ( ) : <EOL> logging . info ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> new_image = self . _ProcessTransforms ( original_image , <EOL> request . transform_list ( ) , <EOL> correct_orientation ) <EOL> substitution_rgb = None <EOL> if input_settings . has_transparent_substitution_rgb ( ) : <EOL> substitution_rgb = input_settings . transparent_substitution_rgb ( ) <EOL> response_value = self . _EncodeImage ( new_image , <EOL> request . output ( ) , <EOL> substitution_rgb ) <EOL> response . mutable_image ( ) . set_content ( response_value ) <EOL> response . set_source_metadata ( source_metadata ) <EOL> def _Dynamic_GetUrlBase ( self , request , response ) : <EOL> self . _blob_stub . GetUrlBase ( request , response ) <EOL> def _Dynamic_DeleteUrlBase ( self , request , response ) : <EOL> self . _blob_stub . DeleteUrlBase ( request , response ) <EOL> def _EncodeImage ( self , image , output_encoding , substitution_rgb = None ) : <EOL> """<STR_LIT>""" <EOL> image_string = StringIO . StringIO ( ) <EOL> image_encoding = "<STR_LIT>" <EOL> if ( output_encoding . mime_type ( ) == images_service_pb . OutputSettings . WEBP ) : <EOL> image_encoding = "<STR_LIT>" <EOL> if ( output_encoding . mime_type ( ) == images_service_pb . OutputSettings . JPEG ) : <EOL> image_encoding = "<STR_LIT>" <EOL> if substitution_rgb : <EOL> blue = substitution_rgb & <NUM_LIT> <EOL> green = ( substitution_rgb >> <NUM_LIT:8> ) & <NUM_LIT> <EOL> red = ( substitution_rgb >> <NUM_LIT:16> ) & <NUM_LIT> <EOL> background = Image . new ( "<STR_LIT>" , image . size , ( red , green , blue ) ) <EOL> background . paste ( image , mask = image . split ( ) [ <NUM_LIT:3> ] ) <EOL> image = background <EOL> else : <EOL> image = image . convert ( "<STR_LIT>" ) <EOL> image . save ( image_string , image_encoding ) <EOL> return image_string . getvalue ( ) <EOL> def _OpenImageData ( self , image_data ) : <EOL> """<STR_LIT>""" <EOL> if image_data . content ( ) and image_data . has_blob_key ( ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . INVALID_BLOB_KEY ) <EOL> if image_data . has_blob_key ( ) : <EOL> image = self . _OpenBlob ( image_data . blob_key ( ) ) <EOL> else : <EOL> image = self . _OpenImage ( image_data . content ( ) ) <EOL> img_format = image . format <EOL> if img_format not in ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . NOT_IMAGE ) <EOL> return image <EOL> def _OpenImage ( self , image ) : <EOL> """<STR_LIT>""" <EOL> if not image : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . NOT_IMAGE ) <EOL> image = StringIO . StringIO ( image ) <EOL> try : <EOL> return Image . open ( image ) <EOL> except IOError : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_IMAGE_DATA ) <EOL> def _OpenBlob ( self , blob_key ) : <EOL> """<STR_LIT>""" <EOL> storage_key = None <EOL> try : <EOL> gs_info = datastore . Get ( <EOL> datastore . Key . from_path ( GS_INFO_KIND , <EOL> blob_key , <EOL> namespace = '<STR_LIT>' ) ) <EOL> storage_key = gs_info [ '<STR_LIT>' ] <EOL> except datastore_errors . EntityNotFoundError : <EOL> pass <EOL> if not storage_key : <EOL> try : <EOL> key = datastore_types . Key . from_path ( blobstore . BLOB_INFO_KIND , <EOL> blob_key , <EOL> namespace = '<STR_LIT>' ) <EOL> datastore . Get ( key ) <EOL> storage_key = blob_key <EOL> except datastore_errors . Error : <EOL> logging . exception ( '<STR_LIT>' , blob_key ) <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . UNSPECIFIED_ERROR ) <EOL> blobstore_stub = apiproxy_stub_map . apiproxy . GetStub ( "<STR_LIT>" ) <EOL> try : <EOL> blob_file = blobstore_stub . storage . OpenBlob ( storage_key ) <EOL> except IOError : <EOL> logging . exception ( "<STR_LIT>" , blob_key ) <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_IMAGE_DATA ) <EOL> try : <EOL> return Image . open ( blob_file ) <EOL> except IOError : <EOL> logging . exception ( "<STR_LIT>" , <EOL> blob_file , blob_key ) <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_IMAGE_DATA ) <EOL> def _ValidateCropArg ( self , arg ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( arg , float ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> if not ( <NUM_LIT:0> <= arg <= <NUM_LIT:1.0> ) : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> def _CalculateNewDimensions ( self , <EOL> current_width , <EOL> current_height , <EOL> req_width , <EOL> req_height , <EOL> crop_to_fit , <EOL> allow_stretch ) : <EOL> """<STR_LIT>""" <EOL> width_ratio = float ( req_width ) / current_width <EOL> height_ratio = float ( req_height ) / current_height <EOL> if allow_stretch : <EOL> if not req_width or not req_height : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> return req_width , req_height <EOL> elif crop_to_fit : <EOL> if not req_width or not req_height : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> if width_ratio > height_ratio : <EOL> return req_width , int ( width_ratio * current_height ) <EOL> else : <EOL> return int ( height_ratio * current_width ) , req_height <EOL> else : <EOL> if req_width == <NUM_LIT:0> or ( width_ratio > height_ratio and req_height != <NUM_LIT:0> ) : <EOL> return int ( height_ratio * current_width ) , req_height <EOL> else : <EOL> return req_width , int ( width_ratio * current_height ) <EOL> def _Resize ( self , image , transform ) : <EOL> """<STR_LIT>""" <EOL> width = <NUM_LIT:0> <EOL> height = <NUM_LIT:0> <EOL> if transform . has_width ( ) : <EOL> width = transform . width ( ) <EOL> if width < <NUM_LIT:0> or <NUM_LIT> < width : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> if transform . has_height ( ) : <EOL> height = transform . height ( ) <EOL> if height < <NUM_LIT:0> or <NUM_LIT> < height : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> crop_to_fit = transform . crop_to_fit ( ) <EOL> allow_stretch = transform . allow_stretch ( ) <EOL> current_width , current_height = image . size <EOL> new_width , new_height = self . _CalculateNewDimensions ( current_width , <EOL> current_height , <EOL> width , <EOL> height , <EOL> crop_to_fit , <EOL> allow_stretch ) <EOL> new_image = image . resize ( ( new_width , new_height ) , Image . ANTIALIAS ) <EOL> if crop_to_fit and ( new_width > width or new_height > height ) : <EOL> left = int ( ( new_width - width ) * transform . crop_offset_x ( ) ) <EOL> top = int ( ( new_height - height ) * transform . crop_offset_y ( ) ) <EOL> right = left + width <EOL> bottom = top + height <EOL> new_image = new_image . crop ( ( left , top , right , bottom ) ) <EOL> return new_image <EOL> def _Rotate ( self , image , transform ) : <EOL> """<STR_LIT>""" <EOL> degrees = transform . rotate ( ) <EOL> if degrees < <NUM_LIT:0> or degrees % <NUM_LIT> != <NUM_LIT:0> : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> degrees %= <NUM_LIT> <EOL> degrees = <NUM_LIT> - degrees <EOL> return image . rotate ( degrees ) <EOL> def _Crop ( self , image , transform ) : <EOL> """<STR_LIT>""" <EOL> left_x = <NUM_LIT:0.0> <EOL> top_y = <NUM_LIT:0.0> <EOL> right_x = <NUM_LIT:1.0> <EOL> bottom_y = <NUM_LIT:1.0> <EOL> if transform . has_crop_left_x ( ) : <EOL> left_x = transform . crop_left_x ( ) <EOL> self . _ValidateCropArg ( left_x ) <EOL> if transform . has_crop_top_y ( ) : <EOL> top_y = transform . crop_top_y ( ) <EOL> self . _ValidateCropArg ( top_y ) <EOL> if transform . has_crop_right_x ( ) : <EOL> right_x = transform . crop_right_x ( ) <EOL> self . _ValidateCropArg ( right_x ) <EOL> if transform . has_crop_bottom_y ( ) : <EOL> bottom_y = transform . crop_bottom_y ( ) <EOL> self . _ValidateCropArg ( bottom_y ) <EOL> width , height = image . size <EOL> box = ( int ( round ( left_x * width ) ) , <EOL> int ( round ( top_y * height ) ) , <EOL> int ( round ( right_x * width ) ) , <EOL> int ( round ( bottom_y * height ) ) ) <EOL> return image . crop ( box ) <EOL> @ staticmethod <EOL> def _GetExifFromImage ( image ) : <EOL> if hasattr ( image , "<STR_LIT>" ) : <EOL> try : <EOL> from PIL import TiffImagePlugin <EOL> return image . _getexif ( ) <EOL> except ImportError : <EOL> logging . info ( '<STR_LIT>' ) <EOL> return None <EOL> @ staticmethod <EOL> def _ExtractMetadata ( image , parse_metadata ) : <EOL> """<STR_LIT>""" <EOL> def ExifTimeToUnixtime ( exif_time ) : <EOL> """<STR_LIT>""" <EOL> regexp = re . compile ( r"<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> match = regexp . match ( exif_time ) <EOL> if match is None : return None <EOL> try : <EOL> date = datetime . datetime ( * map ( int , filter ( None , match . groups ( ) ) ) ) <EOL> except ValueError : <EOL> logging . info ( "<STR_LIT>" , exif_time ) <EOL> return None <EOL> return int ( time . mktime ( date . timetuple ( ) ) ) <EOL> metadata_dict = ( <EOL> parse_metadata and ImagesServiceStub . _GetExifFromImage ( image ) or { } ) <EOL> metadata_dict [ <NUM_LIT> ] , metadata_dict [ <NUM_LIT> ] = image . size <EOL> if _EXIF_DATETIMEORIGINAL_TAG in metadata_dict : <EOL> date_ms = ExifTimeToUnixtime ( metadata_dict [ _EXIF_DATETIMEORIGINAL_TAG ] ) <EOL> if date_ms : <EOL> metadata_dict [ _EXIF_DATETIMEORIGINAL_TAG ] = date_ms <EOL> else : <EOL> del metadata_dict [ _EXIF_DATETIMEORIGINAL_TAG ] <EOL> metadata = dict ( [ ( _EXIF_TAGS [ k ] , v ) <EOL> for k , v in metadata_dict . iteritems ( ) <EOL> if k in _EXIF_TAGS ] ) <EOL> return simplejson . dumps ( metadata ) <EOL> def _CorrectOrientation ( self , image , orientation ) : <EOL> """<STR_LIT>""" <EOL> if orientation == <NUM_LIT:2> : <EOL> image = image . transpose ( Image . FLIP_LEFT_RIGHT ) <EOL> elif orientation == <NUM_LIT:3> : <EOL> image = image . rotate ( <NUM_LIT> ) <EOL> elif orientation == <NUM_LIT:4> : <EOL> image = image . transpose ( Image . FLIP_TOP_BOTTOM ) <EOL> elif orientation == <NUM_LIT:5> : <EOL> image = image . transpose ( Image . FLIP_TOP_BOTTOM ) <EOL> image = image . rotate ( <NUM_LIT> ) <EOL> elif orientation == <NUM_LIT:6> : <EOL> image = image . rotate ( <NUM_LIT> ) <EOL> elif orientation == <NUM_LIT:7> : <EOL> image = image . transpose ( Image . FLIP_LEFT_RIGHT ) <EOL> image = image . rotate ( <NUM_LIT> ) <EOL> elif orientation == <NUM_LIT:8> : <EOL> image = image . rotate ( <NUM_LIT> ) <EOL> return image <EOL> def _ProcessTransforms ( self , image , transforms , correct_orientation ) : <EOL> """<STR_LIT>""" <EOL> new_image = image <EOL> if len ( transforms ) > images . MAX_TRANSFORMS_PER_REQUEST : <EOL> raise apiproxy_errors . ApplicationError ( <EOL> images_service_pb . ImagesServiceError . BAD_TRANSFORM_DATA ) <EOL> orientation = <NUM_LIT:1> <EOL> if correct_orientation : <EOL> exif = self . _GetExifFromImage ( image ) <EOL> if not exif or _EXIF_ORIENTATION_TAG not in exif : <EOL> correct_orientation = False <EOL> else : <EOL> orientation = exif [ _EXIF_ORIENTATION_TAG ] <EOL> width , height = new_image . size <EOL> if height > width : <EOL> orientation = <NUM_LIT:1> <EOL> for transform in transforms : <EOL> if ( correct_orientation and <EOL> not ( transform . has_crop_left_x ( ) or <EOL> transform . has_crop_top_y ( ) or <EOL> transform . has_crop_right_x ( ) or <EOL> transform . has_crop_bottom_y ( ) ) and <EOL> not transform . has_horizontal_flip ( ) and <EOL> not transform . has_vertical_flip ( ) ) : <EOL> new_image = self . _CorrectOrientation ( new_image , orientation ) <EOL> correct_orientation = False <EOL> if transform . has_width ( ) or transform . has_height ( ) : <EOL> new_image = self . _Resize ( new_image , transform ) <EOL> elif transform . has_rotate ( ) : <EOL> new_image = self . _Rotate ( new_image , transform ) <EOL> elif transform . has_horizontal_flip ( ) : <EOL> new_image = new_image . transpose ( Image . FLIP_LEFT_RIGHT ) <EOL> elif transform . has_vertical_flip ( ) : <EOL> new_image = new_image . transpose ( Image . FLIP_TOP_BOTTOM ) <EOL> elif ( transform . has_crop_left_x ( ) or <EOL> transform . has_crop_top_y ( ) or <EOL> transform . has_crop_right_x ( ) or <EOL> transform . has_crop_bottom_y ( ) ) : <EOL> new_image = self . _Crop ( new_image , transform ) <EOL> elif transform . has_autolevels ( ) : <EOL> logging . info ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> logging . warn ( "<STR_LIT>" ) <EOL> if correct_orientation : <EOL> new_image = self . _CorrectOrientation ( new_image , orientation ) <EOL> correct_orientation = False <EOL> return new_image </s>
