Guest User

Untitled

a guest
May 21st, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. def annotate_img(image, service, layers, environ, query_extent, **kw):
  2.  
  3. # Required opacity of watermark
  4. opacity = float(0.5)
  5.  
  6. # Get path to watermark png
  7. wm_path = Image.open(os.path.join(os.path.dirname(__file__), 'watermark_256.png'))
  8.  
  9. # Grab tile and Convert to RGBA
  10. img = image.as_image()
  11. if img.mode != 'RGBA':
  12. img = img.convert('RGBA')
  13.  
  14. # Create new RGBA image for watermark
  15. wm = Image.new('RGBA', img.size, (0,0,0,0))
  16. wm.paste(wm_path)
  17.  
  18. # Adjust opacity of watermark
  19. alpha = wm.split()[3]
  20. alpha_c = ImageEnhance.Brightness(alpha).enhance(opacity)
  21. wm.putalpha(alpha_c)
  22.  
  23. # Create new composite image using the wm as a mask
  24. compo = Image.composite(wm, img, wm)
  25. final_img = Image.new('RGBA', img.size, (0,0,0,0))
  26. final_img.paste(compo)
  27.  
  28. return ImageSource(final_img, image.image_opts)
  29.  
  30. self.im.paste(im, box)
  31. ValueError: images do not match
  32.  
  33. self.im.paste(im, box, im)
Add Comment
Please, Sign In to add comment