code: def watermark(im, mark, position, opacity=1):
      
      if opacity < 1:
          mark = reduce_opacity(mark, opacity)
      if im.mode != 'RGBA':
          im = im.convert('RGBA')
      # create a transparent layer the size of the image and draw the
      # watermark in that layer.
      layer = Image.new('RGBA', im.size, (0, 0, 0, 0))
      if position == 'tile':
          for y in range(0, im.size[1], mark.size[1]):
              for x in range(0, im.size[0], mark.size[0]):
                  layer.paste(mark, (x, y))
      elif position == 'scale':
          # scale, but preserve the aspect ratio
          ratio = min(
              float(im.size[0]) / mark.size[0], float(im.size[1]) / mark.size[1])
          w = int(mark.size[0] * ratio)
          h = int(mark.size[1] * ratio)
          mark = mark.resize((w, h))
          layer.paste(mark, (int((im.size[0] - w) / 2),
                             int((im.size[1] - h) / 2)))
      else:
          layer.paste(mark, position)
      # composite the watermark with the layer
      return Image.composite(layer, im, layer)
docs: Adds a watermark to an image.