Guest User

Untitled

a guest
Jan 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. #!/usr/bin/python
  2. import base64
  3. import Image
  4. import os
  5.  
  6. # image_list = [{filname:'...', anchor: {top, left}}, ...]
  7. def merge(image_list, output_file = None):
  8.     if type(image_list) is not list:
  9.         raise Exception('first argument is not a list')
  10.     if len(image_list) < 2:
  11.         raise Exception('image_list to short')
  12.     if not output_file:
  13.         filename_result = ''  
  14.         for image in image_list:
  15.             filename_result += image['filename']
  16.         filename_result = base64.encodestring(filename_result)
  17.         filename_result += '.png'
  18.     else:
  19.         filename_result = output_file
  20.     print(filename_result)
  21.     if not os.path.isfile(filename_result):
  22.         image_result = Image.open(image_list[0]['filename'])
  23.         image_result.show()
  24.         for image in image_list:
  25.             image_result.paste(image['filename'], (image['anchor']['top'], \
  26.                         image['anchor']['top']), image['filename'])
  27.         image_result.save(filename_result)
  28.     return filename_result
  29.  
  30. def sample():
  31.     return [{'filename':'marker_base.png',
  32.              'anchor':{
  33.                        'top':0,
  34.                        'left':0
  35.                       }
  36.             },
  37.             {'filename':'overlay_education.png',
  38.              'anchor':{
  39.                        'top':0,
  40.                        'left':0
  41.                       }
  42.             },]
Add Comment
Please, Sign In to add comment