<s> """<STR_LIT>""" <EOL> try : <EOL> import Image <EOL> import ImageColor <EOL> except ImportError : <EOL> try : <EOL> from PIL import Image <EOL> from PIL import ImageColor <EOL> except ImportError : <EOL> raise ImportError ( "<STR_LIT>" ) <EOL> def add_reflection ( im , bgcolor = "<STR_LIT>" , amount = <NUM_LIT> , opacity = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> background_color = ImageColor . getrgb ( bgcolor ) <EOL> reflection = im . copy ( ) . transpose ( Image . FLIP_TOP_BOTTOM ) <EOL> background = Image . new ( "<STR_LIT>" , im . size , background_color ) <EOL> start = int ( <NUM_LIT:255> - ( <NUM_LIT:255> * opacity ) ) <EOL> steps = int ( <NUM_LIT:255> * amount ) <EOL> increment = ( <NUM_LIT:255> - start ) / float ( steps ) <EOL> mask = Image . new ( '<STR_LIT:L>' , ( <NUM_LIT:1> , <NUM_LIT:255> ) ) <EOL> for y in range ( <NUM_LIT:255> ) : <EOL> if y < steps : <EOL> val = int ( y * increment + start ) <EOL> else : <EOL> val = <NUM_LIT:255> <EOL> mask . putpixel ( ( <NUM_LIT:0> , y ) , val ) <EOL> alpha_mask = mask . resize ( im . size ) <EOL> reflection = Image . composite ( background , reflection , alpha_mask ) <EOL> reflection_height = int ( im . size [ <NUM_LIT:1> ] * amount ) <EOL> reflection = reflection . crop ( ( <NUM_LIT:0> , <NUM_LIT:0> , im . size [ <NUM_LIT:0> ] , reflection_height ) ) <EOL> composite = Image . new ( "<STR_LIT>" , ( im . size [ <NUM_LIT:0> ] , im . size [ <NUM_LIT:1> ] + reflection_height ) , background_color ) <EOL> composite . paste ( im , ( <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> composite . paste ( reflection , ( <NUM_LIT:0> , im . size [ <NUM_LIT:1> ] ) ) <EOL> return composite </s>
