Created
          April 16, 2014 14:46 
        
      - 
      
- 
        Save hodzanassredin/10887672 to your computer and use it in GitHub Desktop. 
    simple pil(pillow) watermark with shadow processor for django-imagekit(PILKit) sample result https://pbs.twimg.com/media/BlWe6JeCAAAUxru.jpg
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | from PIL import Image | |
| from PIL import ImageFilter | |
| from PIL import ImageOps | |
| from PIL import ImageDraw | |
| from PIL import ImageFont | |
| from PIL import ImageColor | |
| from django.conf import settings | |
| class TextWatermark(object): | |
| def __init__(self, text): | |
| self.text = text | |
| def process(self, image): | |
| width = image.size[0] | |
| font = ImageFont.truetype(settings.WATERMARK_FONT, width/16) | |
| fillcolor = "white" | |
| shadowcolor = "black" | |
| x = 0 | |
| y = 0 | |
| draw = ImageDraw.Draw(image) | |
| draw.text((x-1, y), self.text, font=font, fill=shadowcolor) | |
| draw.text((x+1, y), self.text, font=font, fill=shadowcolor) | |
| draw.text((x, y-1), self.text, font=font, fill=shadowcolor) | |
| draw.text((x, y+1), self.text, font=font, fill=shadowcolor) | |
| draw.text((x, y), self.text, font=font, fill=fillcolor) | |
| del draw | |
| return image | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment